Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infer parameter type from decorator type #680

Open
KotlinIsland opened this issue Jun 6, 2024 · 0 comments
Open

infer parameter type from decorator type #680

KotlinIsland opened this issue Jun 6, 2024 · 0 comments

Comments

@KotlinIsland
Copy link
Owner

def f(fn: Callable[[int], int]):...

f(lambda i: i) # no error, int
@f
def foo(i): # error
    return i # Unknown

real life:

from typing import Callable

from basedtyping import P, T

def copy_signature(fn: Callable[P, T]) -> Callable[[Callable[P, T]], Callable[P, T]]:
    ...

def f(a: int) -> str:
    return str(a)

@copy_signature(f)
def g(a):
    reveal_type(a)  # Unknown
    return ""

reveal_type(g)  # (int) -> str

The function should act like a lambda here and infer the types of the parameters from the surrounding context

copy_signature(f, lambda a: "")  # correctly infers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant