Skip to content

Type variables in Callables don't unify #8275

Open
@maxrothman

Description

@maxrothman

Issue type: Bug
Python version: 3.8
mypy version: 0.760
mypy flags: whatever the defaults are on https://mypy-play.net/

I discovered this issue when playing around with a monad-y Either thing (and here's it working in Typescript)

Here is (I think) a minimal repro:

from typing import Callable, TypeVar, Generic

def foo() -> int:
    return 1

T = TypeVar('T')
bar: Callable[[], T] = foo
main.py:7: error: Incompatible types in assignment (expression has type "Callable[[], int]", variable has type "Callable[[], T]")

I would expect that in the type declaration of bar, T would unify with int, but clearly it does not.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions