-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongpriority-0-hightopic-callsFunction calls, *args, **kwargs, defaultsFunction calls, *args, **kwargs, defaultstopic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issuestopic-type-variables
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.
posita, rmorshea, NeilGirdhar, bersbersbers and sirosen
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongpriority-0-hightopic-callsFunction calls, *args, **kwargs, defaultsFunction calls, *args, **kwargs, defaultstopic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issuestopic-type-variables