Skip to content

Generic function as first argument to map fails #3193

Closed

Description

@JukkaL

From python/typeshed#1178:

map(tuple, [ [2, 3] ]) throws

error: Argument 1 to "map" has incompatible type Tuple[_T_co, ...]; expected Callable[[List[int]], Tuple[_T_co, ...]]

However, this is valid python code.

Here's a more self-contained example that reproduces the problem:

from typing import Callable, TypeVar

T = TypeVar('T')
S = TypeVar('S')

def f(fn: Callable[[T], S], x: T) -> None: pass
def g(x: T) -> T: pass

f(g, 1)  # Argument 1 to "f" has incompatible type Callable[[T], T]; expected Callable[[int], T]

Activity

  1. ilevkivskyi commented on Feb 11, 2019

    @ilevkivskyi
    Member

    I think this is just a duplicate of #1317, passing one generic callable as an argument to another generic callable causes type variables leaking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions