-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make BytesIO inherit from BufferedIOBase. #4082
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
Make BytesIO inherit from BufferedIOBase. #4082
Conversation
The error messages from mypy selftest are quite concerning: |
I'll try that. I removed the explicit inheritance from I'm not really sure how that works, though. I'm unsure how mypy (or other type-checkers) handle that since AFAIK |
I find that a bit weird, since IOBase's
Where
I mean, at least in my mind, it should. Maybe I'm misinterpreting how |
Can you try putting |
Now there's just a minor discrepancy in the argument name of The argument is positional-only though, so I'm not quite sure why stubtest complains about it. @hauntsaninja is that intentional? |
Maybe that's because it should be positional-only in the stub and isn't? It seems it's only positional-only at runtime. Also there are other issues on Python 3.5 and 3.6 apparently:
Maybe those should actually be |
Yeah, it's intentional that stubtest complains about positional-only argument names in this case. In general, it's more permissive for positional-only args, but will complain if the names are totally different. The exact logic is https://github.com/python/mypy/blob/10195b8d3e1fa7a94f9a9c28b9cd10770f1c449a/mypy/stubtest.py#L305 Agreed that it's annoying in this case and that we should whitelist by adding @tarcisioe The double underscore prefix in the stub is interpreted to mean the argument positional-only. For the For the |
I'll tackle those ASAP, @hauntsaninja! Thanks for the explanations. |
@JelleZijlstra @hauntsaninja I had to make some other changes, but as far as I was able to check. they are consistent. Can you guys please take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly concerned about the inheritance from BinaryIO
.
The mypy issue got fixed by the good people of mypy. I did have to add an override for __enter__ similar to what we're doing in python#4082.
The mypy issue got fixed by the good people of mypy. I did have to add an override for __enter__ similar to what we're doing in #4082.
I think all is done now. |
stdlib/3/io.pyi
Outdated
if sys.version_info >= (3, 7): | ||
def read1(self, __size: Optional[int] = ...) -> bytes: ... | ||
def read1(self, __size: int = ...) -> bytes: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this does accept None
, so it should have stayed Optional. Just applied this change myself. If Travis is happy now I'll merge this.
Thanks for getting this tricky change through, @tarcisioe ! |
The mypy issue got fixed by the good people of mypy. I did have to add an override for __enter__ similar to what we're doing in python#4082.
Co-authored-by: Shantanu <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
An attempt at #4075.