get_type_hints() fails on TypedDict inheriting from a generic TypedDict under PEP 563
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
Bug description:
This fails:
from __future__ import annotations
import typing
class TD1[T](typing.TypedDict):
a: T
class TD2(TD1):
pass
print(typing.get_type_hints(TD2))
$ uv run --python=3.13 sample3.py
Traceback (most recent call last):
File "/Users/jelle/py/cpython/sample3.py", line 9, in <module>
print(typing.get_type_hints(TD2))
~~~~~~~~~~~~~~~~~~~~~^^^^^
File "/opt/homebrew/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/typing.py", line 2461, in get_type_hints
value = _eval_type(value, base_globals, base_locals, base.__type_params__)
File "/opt/homebrew/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/typing.py", line 474, in _eval_type
return t._evaluate(globalns, localns, type_params, recursive_guard=recursive_guard)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/typing.py", line 1081, in _evaluate
eval(self.__forward_code__, globalns, localns),
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 1, in <module>
NameError: name 'T' is not defined
Also reproduces on 3.12 and on the latest RC of 3.14.
(Got here while investigating https://github.com/python/cpython/issues/137226#issuecomment-3275500742, but since this variant is a longstanding bug we don't need to fix it for 3.14.0. I want to record and eventually fix it though.)
CPython versions tested on:
CPython main branch, 3.15, 3.14, 3.13, 3.12
Operating systems tested on:
macOS
Linked PRs
- gh-150762
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
Ejecute el reproductor de TypedDict proporcionado en una versión afectada de CPython y, a continuación, inspeccione typing.py en get_type_hints() y la llamada a _eval_type() que se muestra en el traceback. Compare el comportamiento y las pruebas asociadas con el PR vinculado gh-150762; se considera completado cuando el ejemplo resuelve su anotación genérica heredada sin generar NameError.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100