-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
0.930 still gives me "inheriting final" error with an enum.Flag subclass #11850
Comments
* setup: Update mypy to 0.930 * fix: Modernize common.etcd coding style and fix type errors - While pyright (VSCode) supports ParamSpec and Concatenate, mypy 0.930 does not support Concatenate yet. Temporarily comment related lines with "type: ignore". - Introduce a wrapper function to ensure immutable usage of ChainMap which is defined as mutable in typeshed, with minimal runtime overheads. * test: Let test_utils type-checked and workaround python/mypy#11850
* setup: Update mypy to 0.930 * fix: Modernize common.etcd coding style and fix type errors - While pyright (VSCode) supports ParamSpec and Concatenate, mypy 0.930 does not support Concatenate yet. Temporarily comment related lines with "type: ignore". - Introduce a wrapper function to ensure immutable usage of ChainMap which is defined as mutable in typeshed, with minimal runtime overheads. * test: Let test_utils type-checked and workaround python/mypy#11850 Backported-From: main (22.03) Backported-To: 21.09
* setup: Update mypy to 0.930 * fix: Modernize common.etcd coding style and fix type errors - While pyright (VSCode) supports ParamSpec and Concatenate, mypy 0.930 does not support Concatenate yet. Temporarily comment related lines with "type: ignore". - Introduce a wrapper function to ensure immutable usage of ChainMap which is defined as mutable in typeshed, with minimal runtime overheads. * test: Let test_utils type-checked and workaround python/mypy#11850 Backported-From: main (22.03) Backported-To: 21.03
This one is tricky: |
For what it's worth, I've seen others run into this: hikari-py/hikari@d145703#diff-f9118e96adf8379957f11aaba55186744ddfd128aa04bd0929c02ea55325c46cL66-R81 |
Ok, this one is quite complex. The problem is: we don't know most of the time what rhs is during the semantic analysis (value vs method). So, there are several options:
I hope that the amount of false-positives in |
Hello, I'm hitting the same error for the same kind of reason, we have a base enum class where we override class StringEqualityEnum(Enum):
# necessary, as overriding __eq__ discards the __hash__ implementation in Enum.
__hash__ = Enum.__hash__
def __eq__(self, rhs: Any):
if isinstance(self.value, str) and isinstance(rhs, str):
return self.value.lower() == rhs.lower()
return self is rhs An easy workaround is to make it a function: class StringEqualityEnum(Enum):
def __hash__(self):
# necessary, as overriding __eq__ discards the __hash__ implementation in Enum.
return Enum.__hash__(self)
def __eq__(self, rhs: Any):
if isinstance(self.value, str) and isinstance(rhs, str):
return self.value.lower() == rhs.lower()
return self is rhs I think setting |
Ok, there are a lot more rules that we don't support at the moment: https://github.com/python/cpython/blob/549e62827262264cda30455e10e315602129da72/Lib/enum.py#L1538 For example, this will also raise a false-positive: from enum import Enum
class HashEnum(Enum):
__p__ = 1
class Other(HashEnum):
pass Runtime is fine, but type-checker is not: |
Ok, the only way to solve this is to move this logic to My decision to have this in |
How long will it be until this is fixed? It's causing hundreds of mypy errors in my project, making it impossible to upgrade to the latest release, which unfortunately I need as it contains the fix for #11456. If a fix will take some time, can this change to make enums final be reverted in the meantime? Alternatively, could it be made possible to disable this specific check without peppering hundreds of |
Not sure if it's worth a new issue or not. But out of curiosity, should there be support for overriding e.g. dunder-attributes? Below doesn't typecheck, but is fine during runtime. from enum import Enum
class BaseEnum(Enum):
__something__ = 3
class SomeEnum(BaseEnum):
__something__ = 2
|
@flaeppe this is another issue 🙂 |
Bug Report
#11579 seems to fix #11578 in the 0.930 release, but still there are edge cases.
To Reproduce
Here is a minimal reproduction example.
Expected Behavior
It should be accepted in type check.
Actual Behavior
Your Environment
python -m mypy test-enum.py
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: