ParamSpec with Concatenate issue when function has union and kw args with strict=True
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Hi,
Found a strange issue triggered by strict only when kw-args are present in the function.
Below I believe that both function should either pass or fail (I think the correct behavior is pass here)
For reference pyright finds no issues in this snippet
Bug Report
(A clear and concise description of what the bug is.)
To Reproduce
# Ideally, a small sample program that demonstrates the problem.
# Or even better, a reproducible playground link https://mypy-play.net/ (use the "Gist" button)
from typing import Any, Callable, Concatenate, ParamSpec, TypeVar
P = ParamSpec("P")
T = TypeVar("T")
def go(x: Callable[Concatenate[str, P], T], *a: P.args, **k: P.kwargs) -> T:
return x("foo", *a, **k)
def ok(a: str | int, one: int) -> int:
return 1
def error(a: str | int, one: int, **kw: Any) -> int:
return 2
go(ok, 1)
go(error, 1)
mypy playground link here: https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=22221f205a86573a0c4db8cb529dc824
Expected Behavior
No error is reported
Actual Behavior
main.py:15: error: Argument 1 to "go" has incompatible type "Callable[[str | int, int, KwArg(Any)], int]"; expected "Callable[[str, int, KwArg(Any)], int]" [arg-type]
main.py:15: note: This is likely because "error" has named arguments: "a". Consider marking them positional-only
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.9.0
- Mypy command-line flags:
--strict - Mypy configuration options from
mypy.ini(and other config files): - - Python version used: 3.12
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza ejecutando el fragmento de Python proporcionado en el mypy playground enlazado con Python 3.12 y --strict; después, compara los diagnósticos para go(ok) y go(error). Se considera terminado cuando el caso de ParamSpec y Concatenate se comporta de forma coherente con la expectativa indicada y cuenta con cobertura de regresión en mypy.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100