Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Flaw with type aliases containing type variables #2690

Closed
@gvanrossum

Description

@gvanrossum

Reported by @mohabusama on gitter -- short version:

from typing import *
T = TypeVar('T', List[int], Dict)
Processor = Callable[[T], None]
def output2(inp: T, processor: Processor) -> T:
    processor(inp)
def process_dict(inp: Dict) -> None:
    print(inp.keys())
output2([1, 2, 3], process_dict)

There should be an error on the last line, but there isn't. Surrounding the line with reveal_type() shows that the inferred value for T is List[int].

If we expand the type alias Processor inline in the signature of output2() we get the expected error:

__tmp__.py:8: error: Argument 2 to "output2" has incompatible type Callable[[Dict[Any, Any]], None]; expected Callable[[List[int]], None]

This feels like a flaw in @ilevkivskyi's #2378 (which added support for type aliases containing type variables).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions