-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Crash on a project using lots of generics #14783
Comments
Thanks for the crash report! Here's a minimal repro: from typing import Generic, ParamSpec
P = ParamSpec("P")
class Foo(Generic[P]): ...
def checker(foo1: Foo[[int]], foo2: Foo[[str]]) -> None:
foo1 == foo2 Note that, interestingly, this only crashes if you run mypy with |
The crash is reproducible as far back as 0.950, which is the first mypy version that properly supported |
Here's a snippet illustrating mypy's current semantics for some similar cases involving from typing import Callable, Generic, ParamSpec, TypeVar
T = TypeVar("T")
T1 = TypeVar("T1")
P = ParamSpec("P")
P1 = ParamSpec("P1")
class Foo(Generic[T]):
x: T
class Bar(Generic[P]):
x: Callable[P, str]
def checker(foo1: Foo[int], foo2: Foo[str]) -> bool:
return foo1 == foo2 # error: Non-overlapping equality check (left operand type: "Foo[int]", right operand type: "Foo[str]") [comparison-overlap]
def checker1(foo1: Foo[int], foo2: Foo[bool]) -> bool:
return foo1 == foo2
def checker2(foo1: Foo[T], foo2: Foo[T1]) -> tuple[T, T1] | None:
if foo1 == foo2:
return foo1.x, foo2.x
return None
def checker3(bar1: Bar[P], bar2: Bar[P1]) -> tuple[Callable[P, str], Callable[P1, str]] | None:
if bar1 == bar2:
return bar1.x, bar2.x
return None |
… `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`.
… `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`.
Crash Report
source code of the project is at commit 2f2947e4401a3f8d69fa6c77e0108ad110f8af0f of
https://github.com/kode-konveyor/cdd-python
BTW, have you ever thought about adopting the principles of the type system of TypeScript?
They got it quite right. Typing generics in python is still quite a challenge even with 3.11.
See type: ignore comments in the project.
Traceback
To Reproduce
(Write what you did to reproduce the crash. Full source code is
appreciated. We also very much appreciate it if you try to narrow the
source down to a small stand-alone example.)
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: