Skip to content

Use _typeshed.Self with __enter__ - #5712

Merged
JelleZijlstra merged 2 commits into
python:masterfrom
gruebel:adjust-enter-self
Jun 29, 2021
Merged

JelleZijlstra merged 2 commits into
python:masterfrom
gruebel:adjust-enter-self

Conversation

@gruebel

@gruebel gruebel commented Jun 29, 2021

Copy link
Copy Markdown
Contributor

Relates to #5676

I also removed TypeVar usage, where it became obsolete. In cProfile it also made sense to replace the _SelfT references with Self.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I double-checked all these except the Python 2 stuff.

Comment thread stdlib/bz2.pyi

class BZ2File(BaseStream, IO[bytes]):
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't actually exist at runtime; I guess it is inherited from an IO-related base class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, I think it is IOBase, but I would need to check.

@JelleZijlstra
JelleZijlstra merged commit c38171a into python:master Jun 29, 2021
@gruebel
gruebel deleted the adjust-enter-self branch June 30, 2021 19:56
Comment thread stdlib/contextlib.pyi
@graingert

Copy link
Copy Markdown
Contributor

Probably needs a scan for __aenter__ calls

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.

4 participants