-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: ExtensionDtype.name/type as ClassVar #54458
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
Conversation
Since the base EDtype defined it as property previously, going to ClassVar would be an API change that would make it writable (which I think we should make raise) cc @jbrockmendel |
I would agree with that (and the previous PR was aimed to making it a property; it also makes it more explicit that subclasses have to implement it) but in practice, it seems that it has to be a ClassVar (at least for pandas/pandas/core/dtypes/base.py Line 287 in 2451b42
above is called when trying to register a user-defined ExtensionDtype Might be good to discuss ClassVar/property separately for name and type (both are themselves not consistent). edit: When changing these two lines to a property in the pandas-stubs tests, and then run the tests, it fails |
seems like we have a check for .name but not for .type? .type being a property matters for ArrowDtype. In general I follow @simonjayhawkins approach of not wanting to futz with code just to making typing checks happy |
I'm happy to focus only on |
I updated the PR (removed all |
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.
LGTM merge when ready @jbrockmendel
Thanks @twoertwein |
xref #51736
ExtensionDtype.name/type is sometimes a property and sometimes a class variable. Going either way would require non-typing changes. I believe the ClassVar approach is used more frequently and also mandated by some of the register methods.
If ClassVar is the main way of defining type/name, let's annotate as much as possible with that and ignore the few cases that use properties:
I will fix this PR after a decision has been made.