Repository navigation
Fix --strict-equality crash for instances of a class generic over a ParamSpec - #14792
Conversation
This comment has been minimized.
This comment has been minimized.
JukkaL
left a comment
There was a problem hiding this comment.
Thanks for the PR! I think that this can be simplified a bit, but otherwise looks good.
| class Bar(Generic[P]): ... | ||
|
|
||
| def bad1(foo1: Foo[[int]], foo2: Foo[[str]]) -> bool: | ||
| return foo1 == foo2 |
There was a problem hiding this comment.
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, *args, **kwargs, and it is thus compatible with all possible parameters.
There was a problem hiding this comment.
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.
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
… `ParamSpec` (#14792) Fixes #14783. Running mypy on this snippet of code currently causes a crash if you have the `--strict-equality` option enabled: ```python from typing import Generic, ParamSpec P = ParamSpec("P") class Foo(Generic[P]): ... def checker(foo1: Foo[[int]], foo2: Foo[[str]]) -> None: foo1 == foo2 ``` This is because the overlapping-equality logic in `meet.py` currently does not account for the fact that `left` and `right` might both be instances of `mypy.types.Parameters`, leading to this assertion being tripped: https://github.com/python/mypy/blob/800e8ffdf17de9fc641fefff46389a940f147eef/mypy/meet.py#L519 This PR attempts to add the necessary logic to `meet.py` to handle instances of `mypy.types.Parameters`.
Fixes #14783.
Running mypy on this snippet of code currently causes a crash if you have the
--strict-equalityoption enabled:This is because the overlapping-equality logic in
meet.pycurrently does not account for the fact thatleftandrightmight both be instances ofmypy.types.Parameters, leading to this assertion being tripped:mypy/mypy/meet.py
Line 519 in 800e8ff
This PR attempts to add the necessary logic to
meet.pyto handle instances ofmypy.types.Parameters.