New semantic analyzer: some assignments aren't recognized as types if incomplete
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
In the following test case the forward reference to In in the class body doesn't work:
[case testNewAnalyzerNamedTupleCallNested]
from typing import NamedTuple
o: C.Out
i: C.In
reveal_type(o) # E: Revealed type is 'Tuple[Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In], __main__.C.Other, fallback=__main__.C.Out]'
reveal_type(o.x) # E: Revealed type is 'Tuple[builtins.str, __main__.C.Other, fallback=__main__.C.In]'
reveal_type(o.y) # E: Revealed type is '__main__.C.Other'
reveal_type(o.x.t) # E: Revealed type is '__main__.C.Other'
reveal_type(i.t) # E: Revealed type is '__main__.C.Other'
class C:
Out = NamedTuple('Out', [('x', In), ('y', Other)]) # 'In' undefined <<--- should be ok?
In = NamedTuple('In', [('s', str), ('t', Other)])
class Other: pass
The root cause is that if the rvalue of an assignment is incomplete, we add a PlaceholderNode that doesn't have becomes_typeinfo set. This may also affect other things such as assignment-based TypedDicts, type aliases, type variables and NewTypes (haven't checked).
Not sure what would be the best way to fix this. One idea would be to treat every placeholder as a possible type, at least if it's generated from an incomplete assignment. A second idea would be to recognize possible types by looking at an incomplete rvalue, but this doesn't seem always possible.
This is follow-up to #6983.
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
Comienza ejecutando el caso de prueba proporcionado para testNewAnalyzerNamedTupleCallNested e inspecciona cómo la asignación incompleta crea un PlaceholderNode. Comprueba si el mismo comportamiento afecta a los TypedDicts basados en asignaciones, alias de tipo, variables de tipo o NewTypes, como se indica en la issue. Se considera terminado cuando la referencia adelantada se resuelve y se cumplen las expectativas de reveal_type indicadas sin causar regresiones en casos relacionados.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 35/100