Detect if required string literal escapes are missing from a type

Abierto
#948 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
compilers

Línea de trabajo

Start by tracing mypy's semantic analysis for forward references and the handling of quoted versus unquoted type names. Check how class definitions and cyclic imports are represented, and account for the issue's note about type aliases. Done means reporting missing required string-literal escapes, initially within a single module and eventually across cyclic imports.

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

Descripción

feature priority-1-normal topic-quoted-annotations topic-usability

Mypy should complain about code that isn't using string literal escaped when they are required:

class A:
    def (self) -> A: ...   # Should be an error; string literal escape required

Initially we could only detect these cases within a single module. A more general solution would also detect string literal types needed due to cyclic imports.

A simple implementation idea:

  • Tag each instance type with information on whether the type is quoted or not.
  • During semantic analysis, if a type is unquoted but the definition line for the type/class is in the current file but at a later line number, complain.
  • The definition line for a class is actually the line after the end of the class definition. Alternatively, treat classes that are currently being analyzed specially.

We also need deal with type aliases, but this isn't needed for the first iteration.

I think that somebody started working on this a while back, but I can't remember the details. Maybe there is an existing issue as well?

Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Merge medio
1 d 18 h
PR fusionados (30 d)
54

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.

Más de python/mypy

Todos los issues de python/mypy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.