-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: Use Self instead of class-bound TypeVar in pyi files (remove Y019) #51480
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,3 +118,4 @@ dependencies: | |
|
||
- pip: | ||
- sphinx-toggleprompt | ||
- typing_extensions; python_version<"3.11" | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
tzinfo, | ||
) | ||
from os import PathLike | ||
import sys | ||
from typing import ( | ||
TYPE_CHECKING, | ||
Any, | ||
|
@@ -83,8 +84,13 @@ | |
# Name "npt._ArrayLikeInt_co" is not defined [name-defined] | ||
NumpySorter = Optional[npt._ArrayLikeInt_co] # type: ignore[name-defined] | ||
|
||
if sys.version_info >= (3, 11): | ||
from typing import Self | ||
else: | ||
from typing_extensions import Self # pyright: reportUnusedImport = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you could make Self equivalent to Any here. IIRC we did something similar before to enable the latest typing features There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We type check using a single version of Python. There are capabilities in mypy to set the Python version to check against regardless of the version used. We don't do that. So i'm not sure when this import is actually needed. |
||
else: | ||
npt: Any = None | ||
Self: Any = None | ||
|
||
HashableT = TypeVar("HashableT", bound=Hashable) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,4 +87,5 @@ pyyaml | |
requests | ||
pygments | ||
sphinx-toggleprompt | ||
typing_extensions; python_version<"3.11" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this |
||
setuptools>=61.0.0 |
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.
I think we don't need to add it, as it is only used during type checking (and typing_extensions is, I think, a dependency of mypy).
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.
Yes, typing_extension is a dependency of mypy, I just checked for that. We do not want to be explicit, now that we're importing fro typing_extensions?
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.
I think even the stubs packages from typeshed (for example https://pypi.org/project/types-psutil/) do not have typing_extensions as a dependency (neither does pandas-stubs).
If it is a new dependency, it probably should be added to the whatsnew (there might be other places where it needs to be added as well).
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 have had discussions about this before and the outcome was that we do not use typing_extensions.
IIUC we don't need it with the latest mypy (1.0.0) when checking with python 3.11