Skip to content

Problem with sys.stdout.reconfigure and TextIOWrapper partially unknown type #9645

Answered by erictraut
DervishD asked this question in Q&A
Discussion options

You must be logged in to vote

Pyright is working correctly here. I've confirmed that the behavior hasn't changed in pyright for a long time. I suspect that the type definitions for stdio have changed over time, which would explain why you observed a difference in behavior. These type definitions are provided in typeshed and bundled with pyright and pylance.

The type of stdout is defined as TextIO | MaybeNone. The TextIOWrapper type is a subclass of TextIO, but it is defined as generic. It takes a single type argument. When you use the isinstance check to narrow the type of TextIO, pyright has no way of inferring the type argument for TextIOWrapper, so it infers Unknown. If you know the intended type of the type argume…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by DervishD
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants