microsoft / microsoft/pyright

"Type is partially unknown" under very specific circumstances

Open
#10,174 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.