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

Use _typeshed.Self in Python 2, too #6932

Merged
merged 5 commits into from
Jan 16, 2022

Conversation

AlexWaygood
Copy link
Member

Helps unblock PyCQA/flake8-pyi#90.

Prepared with a similar script to #6880.

@github-actions

This comment has been minimized.

@AlexWaygood AlexWaygood marked this pull request as draft January 16, 2022 21:49
@AlexWaygood AlexWaygood marked this pull request as ready for review January 16, 2022 21:55
@github-actions

This comment has been minimized.

@@ -62,7 +62,7 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
__required_keys__: frozenset[str]
__optional_keys__: frozenset[str]
__total__: bool
def copy(self: _T) -> _T: ...
def copy(self: _T) -> _T: ... # noqa: Y019
Copy link
Member

Choose a reason for hiding this comment

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

Why can't this use Self?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because of line 45 — typing_extensions.Self is a _SpecialForm, not a TypeVar. I deliberately excluded typing_extensions from my script for that reason.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe use from _typeshed import Self as _Self?

Copy link
Member Author

@AlexWaygood AlexWaygood Jan 16, 2022

Choose a reason for hiding this comment

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

We'd still need a # noqa comment, though, because the id of the ast.Name node used for the annotation would be _Self rather than Self. PyCQA/flake8-pyi#90 hardcodes it as having to be Self.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could do from _typeshed import Self as TypeshedSelf and it would pass without a # noqa — my proposed Y019 only raises errors for names starting with a leading underscore.

Copy link
Member

Choose a reason for hiding this comment

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

Let's do that, that will also make it obvious that we can switch to PEP 673 Self when that day comes.

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member Author

Oh sorry, you'd already approved 🤪

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor

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

@JelleZijlstra JelleZijlstra merged commit 6a88d5e into python:master Jan 16, 2022
@AlexWaygood AlexWaygood deleted the self-typevars-2 branch January 16, 2022 22:45
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