Detect if required string literal escapes are missing from a type

Aperta
#948 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Merge medio
1g 18h
PR unite (30g)
54

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/mypy

Tutte le issue di python/mypy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.