-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mypy does not honour open()
overrides from typeshed.
#11193
Comments
open()
overrides from typeshed.
Mypy has custom logic for |
Thanks for the heads up @erictraut, in that case I guess the "bug" is more specifically that mypy does not think objects returned by This behaviour would not be a problem if the |
See also python/typeshed#6076 |
This would likely be fixed by #9275, but it hasn't gotten merged for some reason. |
Yeah, Akuli is right that that (at this point quite old) PR will fix. |
Bug Report
It seems like mypy is not honoring the typeshed Path.open overrides exactly, as from these I would expect mypy to think the values returned by open was:
io.TextIOWrapper
for.open("w")
io.BufferedWriter
for.open("wb")
io.FileIO
for.open("wb", buffering=0)
But instead, mypy thinks the values returned are:
typing.TextIO
for.open("w")
typing.BinaryIO
for.open("wb")
typing.BinaryIO
for.open("wb", buffering=0)
The same is the case for the
open()
builtin.I'm reporting this as a mypy issue, because the typing in typeshed looks right to me for the most part, and I can't even tell from typeshed where mypy would be getting
typing.TextIO
from. I will however report a seperate issue against typeshed for mixing theio.
andtyping.IO
heirarchies in return types, as this is maybe wheretyping.BinaryIO
comes from, but even so the other overrides should take precedence as far as I can tell.To Reproduce
The problem can be seen when running mypy on the following code which contain unit tests which run with no errors:
Expected Behavior
I expect mypy to not find any errors in the shared code.
Actual Behavior
Mypy reports the following type errors:
Your Environment
--show-error-codes --show-error-context
mypy.ini
(and other config files):The code for this can be found here
The text was updated successfully, but these errors were encountered: