Sync enum members logic in typeanal and checkmember#19687
Sync enum members logic in typeanal and checkmember#19687hauntsaninja merged 8 commits intopython:masterfrom
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? |
This comment has been minimized.
This comment has been minimized.
|
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: intThen 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 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: 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]
|
Fixes #19686.
Fixes #15540.
Fixes #14600.