-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix --strict-equality
crash for instances of a class generic over a ParamSpec
#14792
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
Changes from 2 commits
1feabc8
c2dc532
e1ff0ed
a3a6902
9a5a411
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1924,3 +1924,49 @@ _testStarUnpackNestedUnderscore.py:10: error: List item 0 has incompatible type | |
_testStarUnpackNestedUnderscore.py:10: error: List item 1 has incompatible type "int"; expected "str" | ||
_testStarUnpackNestedUnderscore.py:11: note: Revealed type is "builtins.list[builtins.str]" | ||
_testStarUnpackNestedUnderscore.py:16: note: Revealed type is "builtins.list[builtins.object]" | ||
|
||
[case testStrictEqualitywithParamSpec] | ||
AlexWaygood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# flags: --strict-equality | ||
from typing import Generic | ||
from typing_extensions import Concatenate, ParamSpec | ||
|
||
P = ParamSpec("P") | ||
|
||
class Foo(Generic[P]): ... | ||
class Bar(Generic[P]): ... | ||
|
||
def bad1(foo1: Foo[[int]], foo2: Foo[[str]]) -> bool: | ||
return foo1 == foo2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all of the comparisons here are technically overlapping (no error should be generated), since the actual underlying callable object could be something that accepts, say, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following e1ff0ed, mypy now only emits an error for the case where the classes are in fact different. I've kept all the test cases for now, but let me know if you'd like some to be removed. They test distinct scenarios that could happen in user code, but they no longer test distinct code paths. |
||
|
||
def bad2(foo1: Foo[[int, str]], foo2: Foo[[int, bytes]]) -> bool: | ||
return foo1 == foo2 | ||
|
||
def bad3(foo1: Foo[[int]], foo2: Foo[[int, int]]) -> bool: | ||
return foo1 == foo2 | ||
|
||
def bad4(foo: Foo[[int]], bar: Bar[[int]]) -> bool: | ||
return foo == bar | ||
|
||
def good1(foo1: Foo[[int]], foo2: Foo[[int]]) -> bool: | ||
return foo1 == foo2 | ||
|
||
def good2(foo1: Foo[[int]], foo2: Foo[[bool]]) -> bool: | ||
return foo1 == foo2 | ||
AlexWaygood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def good3(foo1: Foo[[int, int]], foo2: Foo[[bool, bool]]) -> bool: | ||
return foo1 == foo2 | ||
|
||
def good4(foo1: Foo[[int]], foo2: Foo[P], *args: P.args, **kwargs: P.kwargs) -> bool: | ||
return foo1 == foo2 | ||
|
||
def good5(foo1: Foo[P], foo2: Foo[[int, str, bytes]], *args: P.args, **kwargs: P.kwargs) -> bool: | ||
return foo1 == foo2 | ||
|
||
def good6(foo1: Foo[Concatenate[int, P]], foo2: Foo[[int, str, bytes]], *args: P.args, **kwargs: P.kwargs) -> bool: | ||
return foo1 == foo2 | ||
|
||
[out] | ||
_testStrictEqualitywithParamSpec.py:11: error: Non-overlapping equality check (left operand type: "Foo[[int]]", right operand type: "Foo[[str]]") | ||
_testStrictEqualitywithParamSpec.py:14: error: Non-overlapping equality check (left operand type: "Foo[[int, str]]", right operand type: "Foo[[int, bytes]]") | ||
_testStrictEqualitywithParamSpec.py:17: error: Non-overlapping equality check (left operand type: "Foo[[int]]", right operand type: "Foo[[int, int]]") | ||
_testStrictEqualitywithParamSpec.py:20: error: Non-overlapping equality check (left operand type: "Foo[[int]]", right operand type: "Bar[[int]]") |
Uh oh!
There was an error while loading. Please reload this page.