KotlinIsland / KotlinIsland/basedmypy
infer parameter type from decorator type
- Dominant language
- Python
- Stars
- 202
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
```py
def f(fn: Callable[[int], int]):...
f(lambda i: i) # no error, int
@f
def foo(i): # error
return i # Unknown
```
# real life:
```py
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
```py
copy_signature(f, lambda a: "") # correctly infers
```
Contributor guide
Research direction
Start by running the two Python examples and comparing the decorator case with the working lambda case, including their revealed types. Trace the type-checker entry point for decorator application and parameter inference; done means parameters in the decorated function are inferred from the decorator's callable type without changing the existing lambda behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100