Open
Description
Consider the following two examples, I think they should be equivalent, since logically expansion of type aliases should happen before any other steps. (At least this would be consistent and natural for those familiar with C macros):
from typing import TypeVar, Callable
T = TypeVar('T')
def test1() -> Callable[[T], T]: ...
reveal_type(test1) # Revealed type is 'def () -> def [T] (T`-1) -> T`-1'
reveal_type(test1()) # Revealed type is 'def [T] (T`-1) -> T`-1'
F = Callable[[T], T]
def test2() -> F[T]: ...
reveal_type(test2) # Revealed type is 'def [T] () -> def (T`-1) -> T`-1'
reveal_type(test2()) # Revealed type is 'def (<nothing>) -> <nothing>'
Here test1
works as expected, while if I use an alias something strange happens with test2
. Namely notice a subtle difference between their types.
def () -> def [T] (T`-1) -> T`-1
and
def [T] () -> def (T`-1) -> T`-1
I have noticed few similar scenarios, they all seem to be related to Callable
.