Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

TypeVar with Callable #1115

Open
Cologler opened this issue May 22, 2019 · 3 comments
Open

TypeVar with Callable #1115

Cologler opened this issue May 22, 2019 · 3 comments
Labels
bug Something isn't working feature: analysis

Comments

@Cologler
Copy link

Cologler commented May 22, 2019

from typing import Callable, TypeVar

T = TypeVar('T')

some_cache = []

def lazy(factory: Callable[[], T]):
    # do something ...
    def wrapper() -> T:
        return some_cache[factory]
    return wrapper

fac = lazy(lambda: 15)
value = fac()

Expected behaviour

value has type int.

Actual behaviour

value has no type.

@jakebailey
Copy link
Member

@Cologler
Copy link
Author

Cologler commented May 22, 2019

@jakebailey no sure about that:

image

from typing import TypeVar

T = TypeVar('T')
cache = {}

def convert(value: T) -> T:
    return cache[value]

ret = convert(15)

maybe the test case needs to be updated.

@MikhailArkhipov
Copy link

Moving @jakebailey's example to #1163. Original code requires speclaizing Callable which is part of #535.

@MikhailArkhipov MikhailArkhipov removed their assignment Jun 4, 2019
@MikhailArkhipov MikhailArkhipov changed the title work with TypeVar TypeVar with Callable Jun 4, 2019
@MikhailArkhipov MikhailArkhipov removed this from the June 2019.1 milestone Jun 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working feature: analysis
Projects
None yet
Development

No branches or pull requests

3 participants