-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Sync enum members logic in typeanal and checkmember #19687
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
base: master
Are you sure you want to change the base?
Sync enum members logic in typeanal and checkmember #19687
Conversation
This comment has been minimized.
This comment has been minimized.
All new errors in primer stem from invalid enum definitions in stubs - bare annotations are not considered enum members, even in stubs (both by spec and by common sense). To hide a value, stubs should assign ellipsis to enum members. Here's the relevant spec chapter: https://typing.python.org/en/latest/spec/enums.html#defining-members Do we have direct contact with pandas team? Should I open a ticket to let them know and get that fixed? |
Diff from mypy_primer, showing the effect of this PR on open source code: pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/arrays/period.py:1438: error: "int" has no attribute "value" [attr-defined]
+ pandas/core/arrays/period.py:1442: error: "int" has no attribute "value" [attr-defined]
+ pandas/core/tools/datetimes.py:531: error: "int" has no attribute "value" [attr-defined]
+ pandas/tests/tslibs/test_strptime.py:18: error: "int" has no attribute "value" [attr-defined]
+ pandas/tests/tslibs/test_array_to_datetime.py:22: error: "int" has no attribute "value" [attr-defined]
+ pandas/plotting/_matplotlib/converter.py:534: error: "int" has no attribute "value" [attr-defined]
+ pandas/plotting/_matplotlib/converter.py:539: error: Non-overlapping equality check (left operand type: "FreqGroup", right operand type: "int") [comparison-overlap]
+ pandas/plotting/_matplotlib/converter.py:542: error: Non-overlapping equality check (left operand type: "FreqGroup", right operand type: "int") [comparison-overlap]
+ pandas/plotting/_matplotlib/converter.py:545: error: Non-overlapping equality check (left operand type: "FreqGroup", right operand type: "int") [comparison-overlap]
+ pandas/plotting/_matplotlib/converter.py:548: error: Non-overlapping equality check (left operand type: "FreqGroup", right operand type: "int") [comparison-overlap]
+ pandas/plotting/_matplotlib/converter.py:551: error: Non-overlapping equality check (left operand type: "FreqGroup", right operand type: "int") [comparison-overlap]
+ pandas/plotting/_matplotlib/converter.py:554: error: Non-overlapping equality check (left operand type: "FreqGroup", right operand type: "int") [comparison-overlap]
+ pandas/plotting/_matplotlib/converter.py:691: error: "int" has no attribute "value" [attr-defined]
+ pandas/plotting/_matplotlib/converter.py:911: error: Non-overlapping equality check (left operand type: "FreqGroup", right operand type: "int") [comparison-overlap]
+ pandas/plotting/_matplotlib/converter.py:913: error: Non-overlapping equality check (left operand type: "FreqGroup", right operand type: "int") [comparison-overlap]
+ pandas/plotting/_matplotlib/converter.py:915: error: Non-overlapping equality check (left operand type: "FreqGroup", right operand type: "int") [comparison-overlap]
+ pandas/plotting/_matplotlib/converter.py:917: error: "int" has no attribute "value" [attr-defined]
+ pandas/plotting/_matplotlib/converter.py:917: error: Non-overlapping equality check (left operand type: "FreqGroup", right operand type: "int") [comparison-overlap]
+ pandas/plotting/_matplotlib/timeseries.py:256: error: "int" has no attribute "value" [attr-defined]
python-htmlgen (https://github.com/srittau/python-htmlgen)
+ test_htmlgen/video.py:38: error: Incompatible types in assignment (expression has type "str", variable has type "Preload | None") [assignment]
+ test_htmlgen/form.py:51: error: Incompatible types in assignment (expression has type "str", variable has type "Autocomplete | None") [assignment]
|
cc @Dr-Irv for pandas typing |
Thanks for the ping. Here is what is happening here. We have some enums defined in cython, which is where the values get set. So in our PYI files, we do things like this: class FreqGroup(Enum):
FR_ANN: int
FR_QTR: int
FR_MTH: int
FR_WK: int
FR_BUS: int
FR_DAY: int Then we have code that has things like Now, for the ones we define in cython, we can change this to the actual values in the PYI files. Not ideal - then we have to maintain the numerical values in two places. But we also have some that are dependent on values stored in the C code in numpy. Getting those might be a bit difficult. What's the best way to handle this? |
You can use class FreqGroup(Enum):
FR_ANN = ... https://typing.python.org/en/latest/spec/enums.html#:~:text=Within%20a%20type%20stub,can%20be%20used To include type information, you can use |
I think the following will work: class FreqGroup(Enum):
_value_ : int
FR_ANN = ... and then we won't need to use |
Yeah, we added |
Fixes #19686.
Fixes #15540.
Fixes #14600.