-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Generics type checked but fail at runtime #8366
Copy link
Copy link
Closed
Description
Hey - I have run into an issue where mypy says the code is correct, but then in runtime, if you try to import this code (and not even use it) it will fail with an error.
I'm using mypy 0.761, python 3.8.0 and mypy is in strict mode (can provide exact config if necessary).
Here is the minimal code that replicates it:
from typing import Callable, TypeVar, Generic
T = TypeVar("T")
U = TypeVar("U")
V = TypeVar("V")
Flatmap = Callable[[T], "Foo[V, U]"]
class Foo(Generic[T, U]):
def flatmap(self, mapper: Flatmap[T, U, V]) -> "Foo[V, U]":
...
and here is the error that will show up if you try to import a file that has that code:
raise TypeError(f"Too {'many' if alen > elen else 'few'} parameters for {cls};"
E TypeError: Too many parameters for typing.Callable[[~T], ForwardRef('Foo[V, U]')]; actual 3, expected 1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels