microsoft / microsoft/pyright

Warn on wrong Concatenate usage

Open
#11,251 0 comments 0 reactions 0 assignees View on GitHub
enhancement request
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

I once again fell into the trap of using `Concatenate` inside its own square brackets and not as the first argument as it is intended, e.g. `Callable[[Concatenate[int, P]], None]` while it should be `Callable[Concatenate[int, P], None]`.
This results in some weird assignment errors later on that are hard to interpret:

> "Concatenate[int, (int)]" is not assignable to "int"

Instead (or in combination) there should be an error during the definition.

**Code or Screenshots**
Code sample in [pyright playground](https://pyright-play.net/?enableExperimentalFeatures=true&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoDCAhgDYlEBGJApgDSFgoDGRM1KrdUACkSERADKCak3oBBFHACwAKDnwRhANoAqVdwC6UALyFS5KtWXKCjFmw5tlqGPS2b6AOUbVNcud108%2BA4aIAKACJuIIBKD1kAE2pgKGAwMACiAC5MFDsoCjTbMKgAWgA%2BKBcUajSAOirImLimAAtRAGsA4DSCGwzNMMrq%2BVkG5tbEsKA)

```python
from typing import Callable, Concatenate, ParamSpec

type C[**P] = Callable[[Concatenate[int, P]], None] # no error on misuse

P = ParamSpec("P")

def foo(a: int, b: int) -> None: ...

def check(f: C[int]): ...

check(foo) # "Concatenate[int, (int)]" is not assignable to "int"
```

**VS Code extension or command-line**
1.1.408

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided Python example in the linked pyright playground using version 1.1.408, then trace how Concatenate usage is validated during type definition and assignment checking. Done means the misuse produces a diagnostic at definition time, rather than only the later confusing assignment error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.