Skip to content

type variable escapes in application of higher-order function to a generic function #1506

Closed
@rwbarton

Description

@rwbarton
from typing import TypeVar, Callable
S = TypeVar('S')
def apply(f: Callable[[int], S]) -> S: pass
def g(x: int) -> S: pass
y = apply(g)
reveal_type(y) # E: Revealed type is 'S`-1'

The type of y is not allowed to contain an unbound type variable. There should have been an error Need type annotation for variable on the assignment to y.

(With apply having type def apply(f: Callable[[int], int]) -> S, mypy does give such an error.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions