No error emitted with `ParamSpec` on a signature that is a union of callables with `ParamSpec` and without `ParamSpec`
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 20.6k
- Forks
- 3.3k
- Merge moyen
- 1 j 18 h
- PR mergées (30 j)
- 54
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la reproduction fournie de ParamSpec et Callable-union, puis lisez la discussion pyright liée pour comprendre les interprétations concurrentes. Exécutez-la avec mypy dans l’environnement indiqué et suivez le comportement de vérification de ParamSpec ; la tâche est terminée lorsque le traitement est résolu et couvert par un test de régression ou documenté comme intentionnel.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- devtools
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100