Skip to content
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
wants to merge 2 commits into from
Closed

add _io module #11187

wants to merge 2 commits into from

Conversation

tungol
Copy link
Contributor

@tungol tungol commented Dec 19, 2023

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 #3968

This comment has been minimized.

@tungol tungol marked this pull request as draft December 19, 2023 20:49
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.

Copy link
Contributor

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]

@tungol tungol marked this pull request as ready for review December 19, 2023 21:05
@JelleZijlstra
Copy link
Member

Unfortunately this has severe merge conflicts now. If you fix them, I will review the PR.

@JelleZijlstra
Copy link
Member

Thanks for contributing! I'm closing this PR for now, because it still has a merge conflict
after three months of inactivity. If you are still interested, please feel free to open
a new PR (or ping us to reopen this one).

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
@tungol tungol mentioned this pull request Oct 5, 2024
@tungol tungol deleted the io branch October 10, 2024 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants