-
-
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
Stricter equality checks? #1271
Comments
Hm, I think you're right this should be flagged if the types don't overlap.
|
The operators |
Attempting to specify a type other than
(I'm adding this in case someone else is searching for this error.) |
+1 would love to see this - had to troubleshoot a bug today that turned out to a stray |
It looks like this appears often, so I raise priority to high. |
+1, would love this feature. just had a bug with a missing parens, i.e. |
Kind of similar to the above: I did forget a few times that |
+1 would love to see this too. I'm replacing a bunch of old string values with more type-safe enum objects and would love to get errors in places where my code needs updating, such as: if obj.enum_value == 'my_old_hard_coded_string_value' |
…6370) Fixes #1271 The new per-file flag `--strict-equality` disables equality, identity, and container checks between non-overlapping types. In general the implementation is straightforward. Here are some corner cases I have found: * `Any` should be always safe. * Type promotions should be ignored, `b'abc == 'abc'` should be an error. * Checks like `if x is not None: ...`, are special cased to not be errors if `x` has non-optional type. * `Optional[str]` and `Optional[bytes]` should be considered non-overlapping for the purpose of this flag. * For structural containers and custom `__eq__()` (i.e. incompatible with `object.__eq__()`) I suppress the non-overlapping types error, if there is already an error originating from the method call check. Note that I updated `typing-full.pyi` so that `Sequence` inherits from `Container` (this is needed by some added tests, and also matches real stubs). This however caused necessary changes in a bunch of builtins fixtures.
It would be nice if there was a way to enforce a constraint on
__eq__
-- maybe a warning? I almost never want to do the followingWhile that check may make sense in a world of vanilla python, I'd argue it doesn't make much sense within mypy's world (especially if the arguments are explicitly typed as different types; i.e., one is not a subtype of the other).
The text was updated successfully, but these errors were encountered: