You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from typing import TypeVar
T = TypeVar('T')
U = TypeVar('U')
def outer(x: T) -> T:
def inner(y: U) -> T: ...
return inner(1) # error: Incompatible return value type: expected T`-1, got builtins.int*
I should be able to pass inner a value of any type and get back a T to return from outer. But internally the type variables U and T of inner have the same id (-1) so effectively mypy thinks inner has a type like (U) -> U.
The text was updated successfully, but these errors were encountered:
Yeah, type variables were originally implemented with various restrictions such as no nested (generic) functions that weren't enforced or were lifted later without fixing the underlying issues. The current way of doing type inference of generics also causes the two-namespace-approach to not work correctly in other contexts. (Though I'm not quite sure if generics ever worked without any scoping issues, and the namespace hack was questionable from the beginning.)
I should be able to pass
inner
a value of any type and get back aT
to return fromouter
. But internally the type variablesU
andT
ofinner
have the same id (-1) so effectively mypy thinksinner
has a type like(U) -> U
.The text was updated successfully, but these errors were encountered: