"Type is partially unknown" under very specific circumstances
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
For the following code pyright gives me an error:
```
Type of "c" is partially unknown
Type of "c" is "(str) -> Unknown"
```
```python
from collections.abc import Callable
type Func[T] = Callable[[str], T]
def curry[First, *Rest, Result](function: Callable[[First, *Rest], Result]) -> Callable[[*Rest], Callable[[First], Result]]:
return lambda *rest: lambda first: function(first, *rest)
def id[T](x: T) -> Func[T]: ...
def f[T](x: Func[T]) -> Func[T]: ...
@curry
def add[T](a: Func[T], b: Func[T]) -> Func[T]: ...
a = id(1.0)
b: Func[float] = lambda s: f(d)(s)
c = add(b)(a)
d = a
# d = a
```
The error disappears if I do any of the following:
1. change the return type of `add` from `Func[T]` to `Callable[[str], T]`;
2. change the definition of `d` from `a` to `id(1.0)`;
3. do not curry the `add` function;
4. uncomment the last line.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Python reproducer through Pyright and compare its diagnostic with the four listed changes. Investigate the type inference around the curried add call, the Func alias, and the later assignment to d; done means the original example no longer reports a partially unknown type while the stated typing behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100