No error emitted with `ParamSpec` on a signature that is a union of callables with `ParamSpec` and without `ParamSpec`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
See discussion on pyright at : https://github.com/microsoft/pyright/issues/6796
mypy doesn't emit an error, but pyright does, and it isn't clear which is correct!
We're trying to support something with pandas with DataFrame.pipe() that allows functions with any kind of argument list to be passed. But the function can be specified in one of two ways:
- as a function
- as a tuple, with the tuple being the name of an argument and the function
To Reproduce
from typing import Callable, Concatenate
from typing_extensions import ParamSpec
P = ParamSpec("P")
def func1(x: int):
print(x)
def func2(x: int, /, y: str):
print(x)
def accept_func(
f: Callable[Concatenate[int, P], None] | tuple[int, Callable[..., None]],
*args: P.args,
**kwargs: P.kwargs,
) -> None:
if isinstance(f, tuple):
if args:
f[1](f[0], args)
else:
f[1](f[0])
else:
f(5)
accept_func(func1)
accept_func((2, func1))
accept_func((3, func2), "abc")
Expected Behavior
pyright reports:
pspec.py:26:9 - error: Arguments for ParamSpec "P@accept_func" are missing (reportGeneralTypeIssues)
pspec.py:29:1 - error: Arguments for ParamSpec "P@accept_func" are missing (reportGeneralTypeIssues)
pspec.py:30:25 - error: Arguments for ParamSpec "P@accept_func" are missing (reportGeneralTypeIssues)
pyright authors think mypy should report all 3. See discussion in linked issue.
Actual Behavior
mypy reports:
Success: no issues found in 1 source file
Your Environment
- Mypy version used: 1.7.1
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.11.3
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der bereitgestellten ParamSpec- und Callable-union-Reproduktion und lies dann die verknüpfte pyright-Diskussion, um die konkurrierenden Interpretationen zu verstehen. Führe sie mit mypy in der angegebenen Umgebung aus und verfolge das Prüfverhalten von ParamSpec; abgeschlossen ist die Aufgabe, wenn die Behandlung geklärt und durch einen Regressionstest abgedeckt oder als beabsichtigt dokumentiert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100