-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
TYP: Use Self instead of class-bound TypeVar in pyi files (remove Y019) #51480
TYP: Use Self instead of class-bound TypeVar in pyi files (remove Y019) #51480
Conversation
@@ -117,3 +117,4 @@ dependencies: | |||
|
|||
- pip: | |||
- sphinx-toggleprompt | |||
- typing_extensions; python_version<"3.11" |
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
@@ -86,4 +86,5 @@ feedparser | |||
pyyaml | |||
requests | |||
sphinx-toggleprompt | |||
typing_extensions; python_version<"3.11" |
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 don't think we need this
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.
The Self
changes look good to me. Whether typing_extensions
should be a new dependency or not, should be judged by someone else.
+1 from me, I'm also not sure what is normal. I looked at |
@@ -117,3 +117,4 @@ dependencies: | |||
|
|||
- pip: | |||
- sphinx-toggleprompt | |||
- typing_extensions; python_version<"3.11" |
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
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 comment
The 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 comment
The 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.
This PR was made as a bit of a follow-up to #51309, where @jbrockmendel had a suggestion to use I was not not aware of the decision to not use IMO
|
When we had the discussion before I was arguing for including it. Now that we have pandas-stubs and typing in the codebase could be considered as a glorified linter there are probably less arguments for. Also, it has not always ended up been a blocker for using features supported in the latest mypy by implementing some trivial workarounds in some cases. cc @TomAugspurger @jorisvandenbossche @jreback @WillAyd from previous discussions. |
The previous decision was for a run-time dependency. As the import is inside a TYPE_CHECKING block this implementation only makes it a dev dependency (just like the use of npt)? |
Yes, this will only be active when type checking and it will not be a run time requirement. |
scanning back over the historic typing_extensions discussions, the issue with having it as a dev-only dependency was the the need to wrap in TYPE_CHECKING and was also before typing_extensions was an required dependency of mypy in #27646 |
adding to this list...
|
From looking at the linked issues, #37119 might be the most recent-ish complete discussion issue about this (+ #34869 as a precursor of it). We can maybe have the actual discussion about adding as dependency or not there? From skimming that issue, what is still unclear to me is what the exact consequences are? Is this only a dev dependency (only contributors have to have it installed in their environment) and not a required runtime dependency? Or would it only be useful if it's actually a runtime dependency? Can someone summarize this over at #37119? |
I've answered in #37119 regarding my experience using Wrt. whether If there's an argument for making this available at run time i'm open to arguments, but I just didn't see the need myself. and it makes sense to always limit run time dependencies when possible. |
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.
Thanks @topper-123
doesn't appear there are any objections from anyone this time round.
if part of the argument to use typing_extensions
is that it is a required dependency of mypy, do we need to explicitly include it in environment.yml
requires merge main
lgtm pending green
I've merged main. |
Wow great work @topper-123 |
nice! |
Can someone update #37119 with the outcome? (and probably close it) |
Progress towards #51233. Next up will be to use
Self
in the pandas code base.xref #51309.
CC: @twoertwein