-
Hi there! I have the following code in a program, which I think it's pretty standard:
I'm getting an error from Thing is, I don't know how to get rid of this error except using Am I doing anything wrong here? How can I suppress the error without resorting to dubious code constructs? Is it a bug in I've googled about this problem for days without finding anything and help from Copilot and ChatGPT has been quite useless. Thanks in advance for any information about this. I can't believe I'm the only one wanting to force |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
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 The type of It appears that you're using strict-mode type checking. By default pyright does not report unknown or partially-unknown types. If you don't want to see these errors reported, you can switch from "strict" to "standard" type checking mode. |
Beta Was this translation helpful? Give feedback.
-
@erictraut thanks A LOT for the explanation. I was focused unto TextIOWrapper and forgot about TextIO. And yes, probably the problem is in typeshed, apparently it has been updated since I last worked on the code. Thanks a lot, really, I was worried about some unintended side-effect in the code I was using, even though as I wrote it seems pretty standard. |
Beta Was this translation helpful? Give feedback.
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 asTextIO | MaybeNone
. TheTextIOWrapper
type is a subclass ofTextIO
, but it is defined as generic. It takes a single type argument. When you use theisinstance
check to narrow the type ofTextIO
, pyright has no way of inferring the type argument forTextIOWrapper
, so it infersUnknown
. If you know the intended type of the type argume…