-
Notifications
You must be signed in to change notification settings - Fork 42
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
Type stub incompatiblity with tarfile.ExFileObject (i.e. tarfile.TarFile.extractfile() result) #214
Comments
Thanks for bringing this up! I'd like to hear what @hauntsaninja has to say here, as they are far more knowledgeable in Python typing than I am. It seems to me that Perhaps tarfile should move to using We can consider moving to using a custom |
I think using something like I think BinaryIO should be avoided. There's not really any difference between it and IO[bytes] and it mainly just serves to confuse. In general, typeshed tries to avoid use of BinaryIO and TextIO, and even of IO. These things were added to the stdlib before protocols were a thing. In practice they often don't work well because it turns out there's a tonne of variation in what "file-like" actually means, and they don't capture well the difference between readers and writers. There's more discussion at python/typing#829 |
Thanks for the fix. Would you also submit it to |
We don't need to change tomllib, since nothing looks at type hints in the standard library; everything just looks at typeshed |
Yup, and typeshed already uses SupportsRead so you shouldn't have this issue with |
Well, I did look at types in the stdlib at first and took me quite a while to figure out why mypy complains about tomli and not the "identical" types in tomllib. |
Please consider the following snippet:
When I run mypy on it, I get:
To be honest, typing docs don't really say what the difference between
IO[bytes]
andBinaryIO
is. Besides type stubs, the code works. FWICS, tomllib would suffer from the same problem if not for the fact that mypy overrides its type stub to:The text was updated successfully, but these errors were encountered: