python / python/typeshed

Using typing.NoDefault instead of Ellipsis [3.13]

Abierto
#12,102 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
5.1k
Forks
2.1k
Merge medio
1 d 19 h
PR fusionados (30 d)
82

Descripción

ParamSpec, TypeVar, TypeVarTuple have a __default__ attribute, which is evaluated to NoDefault, when no default is provided in constructor :

from typing import ParamSpec, TypeVar, TypeVarTuple, Any

print(f'{TypeVar("Plop").__default__ = }')
...

# ❯ python3.13 /tmp/tmpe9xlgjg8.py
TypeVar("Plop").__default__ = typing.NoDefault
TypeVarTuple("Plop").__default__ = typing.NoDefault
ParamSpec("Plop").__default__ = typing.NoDefault

TypeVar("Plop", default=Any).__default__ = typing.Any
TypeVarTuple("Plop", default=Any).__default__ = typing.Any
ParamSpec("Plop", default=Any).__default__ = typing.Any

But this behaviour is not implemented in stubs, Ellipsis is used instead of typing.NoDefault which is already in stubs. I guess it could be fixed without breaking risks.

diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi
index f04b2d858..a84a517cc 100644
--- a/stdlib/typing.pyi
+++ b/stdlib/typing.pyi
@@ -161,7 +161,7 @@ class TypeVar:
             contravariant: bool = False,
             covariant: bool = False,
             infer_variance: bool = False,
-            default: Any = ...,
+            default: Any = NoDefault,
         ) -> None: ...
     elif sys.version_info >= (3, 12):
         def __init__(
@@ -231,7 +231,7 @@ if sys.version_info >= (3, 11):
             def __default__(self) -> Any: ...
             def has_default(self) -> bool: ...
         if sys.version_info >= (3, 13):
-            def __init__(self, name: str, *, default: Any = ...) -> None: ...
+            def __init__(self, name: str, *, default: Any = NoDefault) -> None: ...
         else:
             def __init__(self, name: str) -> None: ...
 
@@ -279,7 +279,7 @@ if sys.version_info >= (3, 10):
                 contravariant: bool = False,
                 covariant: bool = False,
                 infer_variance: bool = False,
-                default: Any = ...,
+                default: Any = NoDefault,
             ) -> None: ...
         elif sys.version_info >= (3, 12):
             def __init__(

Ps :

print(f'{TypeVar("Plop").__default__ is TypeVarTuple("Plop").__default__ is ParamSpec("Plop").__default__ = }')
❯ python3.13 /tmp/tmpe9xlgjg8.py
TypeVar("Plop").__default__ is TypeVarTuple("Plop").__default__ is ParamSpec("Plop").__default__ = True
TypeVar("Plop").__default__ is Ellipsis = False

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Revisa las definiciones de TypeVar, TypeVarTuple y ParamSpec en stdlib/typing.pyi, centrándote en sus parámetros predeterminados y en el stub NoDefault existente. Actualiza las signaturas de Python 3.13 para que los valores predeterminados omitidos correspondan a typing.NoDefault y confirma que el stub ya no los representa como Ellipsis.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
tooling
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.