-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
add _io module #11187
Closed
Closed
add _io module #11187
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment has been minimized.
This comment has been minimized.
In addition to shuffling defintions between files, these things got tweaked: - I moved BufferedIOBase.raw to the child classes which *do* define that attribute on themselves - Removed several redundant definitions of __enter__. These seem to be an artifact of using TypeVar instead of Self originally - seek and truncate have inconsistent variable names. They're also positional only, so they were in the stubtest allowlist before, but I went ahead and made them explicit in the stubs - BytesIO.readlines shouldn't have been on the allowlist in the first place. It differs not only in variable name, but also default value. - A big block of functions in TextIOWrapper were commented that mypy needed them, but I don't think it does anymore, unless there's a problem with subclassing TextIOWrapper that doesn't show up in typeshed itself. No indication in the history about that. - In the implementation, the concrete classes inherit from the private implementation _*IOBase classes, not the classes in io which are actually metaclasses, but they are registered to those metaclasses at runtime. It wasn't technically required for any reason, but I split the difference on this by keeping the _*IOBase classes in their base classes directly. I think it's a bit of a reminder of the actual implementation, and means that a stubtest check for inheritance will show that typeshed is adding to the base classes, rather than replacing the base class, and I think that's a little cleaner. Partially related to python#3968
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: rich (https://github.com/Textualize/rich)
- rich/progress.py:173: error: Definition of "writelines" in base class "IOBase" is incompatible with definition in base class "IO" [misc]
+ rich/progress.py:173: error: Definition of "writelines" in base class "_IOBase" is incompatible with definition in base class "IO" [misc]
operator (https://github.com/canonical/operator)
- ops/pebble.py:1631: error: Argument 1 of "write" is incompatible with supertype "BufferedIOBase"; supertype defines the argument type as "Buffer" [override]
+ ops/pebble.py:1631: error: Argument 1 of "write" is incompatible with supertype "_BufferedIOBase"; supertype defines the argument type as "Buffer" [override]
- ops/pebble.py:1655: error: Return type "str | bytes" of "read" incompatible with return type "bytes" in supertype "BufferedIOBase" [override]
+ ops/pebble.py:1655: error: Return type "str | bytes" of "read" incompatible with return type "bytes" in supertype "_BufferedIOBase" [override]
- ops/pebble.py:1655: error: Argument 1 of "read" is incompatible with supertype "BufferedIOBase"; supertype defines the argument type as "int | None" [override]
+ ops/pebble.py:1655: error: Argument 1 of "read" is incompatible with supertype "_BufferedIOBase"; supertype defines the argument type as "int | None" [override]
- ops/pebble.py:1688: error: Return type "str | bytes" of "read1" incompatible with return type "bytes" in supertype "BufferedIOBase" [override]
+ ops/pebble.py:1688: error: Return type "str | bytes" of "read1" incompatible with return type "bytes" in supertype "_BufferedIOBase" [override]
|
Unfortunately this has severe merge conflicts now. If you fix them, I will review the PR. |
Thanks for contributing! I'm closing this PR for now, because it still has a merge conflict |
tungol
added a commit
to tungol/typeshed
that referenced
this pull request
Oct 5, 2024
This is an updated version of python#11187 In addition to shuffling defintions between files, these things got tweaked: - Removed several redundant definitions of __enter__. These seem to be an artifact of using TypeVar instead of Self originally - seek and truncate have inconsistent variable names. They're also positional only, so they were in the stubtest allowlist before, but I went ahead and made them explicit in the stubs - BytesIO.readlines shouldn't have been on the allowlist in the first place. It differs not only in variable name, but also default value. - A big block of functions in TextIOWrapper were commented that mypy needed them, but I don't think it does anymore, unless there's a problem with subclassing TextIOWrapper that doesn't show up in typeshed itself. No indication in the history about that. - In the implementation, the concrete classes inherit from the private implementation _*IOBase classes, not the classes in io which are actually metaclasses, but they are registered to those metaclasses at runtime. It wasn't technically required for any reason, but I split the difference on this by keeping the _*IOBase classes in their base classes directly. I think it's a bit of a reminder of the actual implementation, and means that a stubtest check for inheritance will show that typeshed is adding to the base classes, rather than replacing the base class, and I think that's a little cleaner. Partially related to python#3968
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In addition to shuffling defintions between files, these things got tweaked:
Partially related to #3968