-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: use Self for type checking #51233
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
Comments
Pandas-stubs is using If enforcing Self is important, it might be good to wait until ruff implements more of the flake8-pyi checks and hope that they also implement it for regular py files. |
The main benefit of adding
and
So I don't think this should be connected to updates to ruff. |
I'm all for Self but it would also be nice to enforce it: you can achieve exactly the same with TypeVars already - so it would be nice to discourage TypeVars in cases where Self would be a more readable alternative (which flake-8pyi does for pyi files). Obviously, we could already start using Self (typing_extensions wouldn't even need to be a runtime dependency). |
I guess a first step would be to enable Y019 by removing it here https://github.com/pandas-dev/pandas/blob/main/setup.cfg#L19 |
If Self is no more than syntactic sugar then this is probably not a strong enough argument alone to adopt typing_extensions for the pandas codebase at this time. But I'm sure that other features such as TypeGuard could be #51309 Obviously, if/when typing_extensions is a dev-only dependency for pandas, then it makes sense to keep the pandas types annotations consistent with pandas-stubs and use Self. But for now, -1 |
We recently upgraded the mypy requirement to mypy v1.0. One of the new capabilities of mypy 1.0 is that it can now type check the
Self
type. I propose we useSelf
for self type checking in Pandas instead if as we currently do, usingTypeVar
s.One issue with type checking using
Self
, is thatSelf
was added only in python 3.11, while Pandas supports Python >= 3.8. However,Self
has been added totyping_extensions
, so if we addtype_extensions
as a Pandas dependency for Python <3.11, we can useSelf
for type checking purposes in Pandas.The text was updated successfully, but these errors were encountered: