Open
Description
Bug report
Bug description:
When setting the default of an argument to sys.stdout and the type is argparse.FileType("wb")
then the class should be _io.BufferedWriter
not _io.TextIOWrapper
when no arguments are provided. When the argument is set to -
then the class is correctly set to _io.BufferedWriter
as expected.
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument("outfile", nargs="?", type=argparse.FileType("wb"), default=sys.stdout)
args = parser.parse_args("-")
print(type(args.outfile))
# <class '_io.BufferedWriter'>
# Correct
args = parser.parse_args()
print(type(args.outfile))
# <class '_io.TextIOWrapper'>
# Incorrect
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
Python modules in the Lib dirPython modules in the Lib dirAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
No status