-
-
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
Use _typeshed.Self
in Python 2, too
#6932
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
stdlib/typing_extensions.pyi
Outdated
@@ -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 |
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.
Why can't this use Self?
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.
Because of line 45 — typing_extensions.Self
is a _SpecialForm
, not a TypeVar
. I deliberately excluded typing_extensions
from my script for that reason.
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.
Maybe use from _typeshed import Self as _Self
?
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.
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
.
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.
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.
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.
Let's do that, that will also make it obvious that we can switch to PEP 673 Self when that day comes.
This comment has been minimized.
This comment has been minimized.
Oh sorry, you'd already approved 🤪 |
This comment has been minimized.
This comment has been minimized.
1 similar comment
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Helps unblock PyCQA/flake8-pyi#90.
Prepared with a similar script to #6880.