python / python/mypy

No error emitted with `ParamSpec` on a signature that is a union of callables with `ParamSpec` and without `ParamSpec`

Aperta
#16,702 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione fornita di ParamSpec e Callable-union, quindi leggi la discussione collegata di pyright per comprendere le interpretazioni concorrenti. Eseguila con mypy nell’ambiente indicato e traccia il comportamento di controllo di ParamSpec; il lavoro è concluso quando la gestione è stata risolta e coperta da un test di regressione oppure documentata come intenzionale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.