`generics_defaults.py` mandates that type checkers should allow a class that raises `TypeError` at runtime
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- python
- Área
- documentation, testing
Línea de trabajo
Comienza con conformance/tests/generics_defaults.py en las líneas 191-200 y compara su requisito con la especificación de typing. Después, inspecciona typing.py en _collect_type_parameters y reproduce los ejemplos en las versiones de sintaxis de Python citadas. Se considera terminado cuando se haya decidido si el runtime o la especificación y la prueba de conformance son inconsistentes, con cobertura de regresión para la corrección elegida.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
This test mandates that type checkers should allow classes that have ParamSpecs-with-defaults following TypeVarTuples: https://github.com/python/typing/blob/22d9392a5ead302cc02c47ecbbcf3aa40106fd9f/conformance/tests/generics_defaults.py#L191-L200
But these fail at runtime. Using Python 3.11 syntax:
% uvx python3.14
Python 3.14.0 (main, Oct 10 2025, 12:54:13) [Clang 20.1.4 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import *
>>> Ts = TypeVarTuple("Ts")
>>> P = ParamSpec("P", default=[int, str])
>>> class A(Generic[*Ts, P]): ...
...
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
class A(Generic[*Ts, P]): ...
~~~~~~~^^^^^^^^
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 402, in inner
return func(*args, **kwds)
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 1157, in _generic_class_getitem
return _GenericAlias(cls, args)
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 1334, in __init__
self.__parameters__ = _collect_type_parameters(
~~~~~~~~~~~~~~~~~~~~~~~~^
args,
^^^^^
enforce_default_ordering=enforce_default_ordering,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 291, in _collect_type_parameters
raise TypeError('Type parameter with a default'
' follows TypeVarTuple')
TypeError: Type parameter with a default follows TypeVarTuple
Using Python <=3.10 syntax:
>>> class B(Generic[Unpack[Ts], P]): ...
...
Traceback (most recent call last):
File "<python-input-4>", line 1, in <module>
class B(Generic[Unpack[Ts], P]): ...
~~~~~~~^^^^^^^^^^^^^^^
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 402, in inner
return func(*args, **kwds)
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 1157, in _generic_class_getitem
return _GenericAlias(cls, args)
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 1334, in __init__
self.__parameters__ = _collect_type_parameters(
~~~~~~~~~~~~~~~~~~~~~~~~^
args,
^^^^^
enforce_default_ordering=enforce_default_ordering,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 291, in _collect_type_parameters
raise TypeError('Type parameter with a default'
' follows TypeVarTuple')
TypeError: Type parameter with a default follows TypeVarTuple
And using Python 3.13+ syntax:
>>> class C[*Ts, **P = [int, str]]: ...
...
Traceback (most recent call last):
File "<python-input-5>", line 1, in <module>
class C[*Ts, **P = [int, str]]: ...
File "<python-input-5>", line 1, in <generic parameters of C>
class C[*Ts, **P = [int, str]]: ...
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 1334, in __init__
self.__parameters__ = _collect_type_parameters(
~~~~~~~~~~~~~~~~~~~~~~~~^
args,
^^^^^
enforce_default_ordering=enforce_default_ordering,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/alexw/Library/Application Support/uv/python/cpython-3.14.0-macos-aarch64-none/lib/python3.14/typing.py", line 291, in _collect_type_parameters
raise TypeError('Type parameter with a default'
' follows TypeVarTuple')
TypeError: Type parameter with a default follows TypeVarTuple
Since it seems that the tests are quoting the spec here, is this a bug in the runtime implementation of the typing module? Or should we update the spec and the conformance suite to allow type checkers to catch this runtime error?
- Lenguaje dominante
- Python
- Estrellas
- 1.8k
- Forks
- 302
- Merge medio
- 23 h
- PR fusionados (30 d)
- 8
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
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.
Más de python/typing
-
topic: typing spec
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
topic: typing spec
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
topic: documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
topic: documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
topic: conformance tests topic: typing spec
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
Todos los issues de python/typing
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
learningequality/ricecooker#747 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
run-llama/llama_index#23199 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
KhronosGroup/glTF-Blender-IO#2769 ·