Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

argparse: type=FileType("wb"), default=sys.stdout returns _io.TextIOWrapper instead of _io.BufferedWriter #134410

Open
Labels
stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
@Chaz6

Description

@Chaz6

Bug report

Bug description:

When setting the default of an argument to sys.stdout and the type isargparse.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.

importargparseimportsysparser=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'># Correctargs=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

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp