Confusing syntax error for missing comma after import-as target
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
Bug description:
Right now we have:
>>> import a as a b
File "<python-input-0>", line 1
import a as a b
^
SyntaxError: cannot use name as import target
>>> from x import a as a b
File "<python-input-1>", line 1
from x import a as a b
^
SyntaxError: cannot use name as import target
This happens since these cases match these two rules.
One possible fix would be to add NAME to the list of not-matched tokens so that the current rules don't match this case.
However, I have an idea for a slightly nicer error. PR forthcoming.
cc @pablogsal @lysnikolaou @sobolevn
CPython versions tested on:
3.14, 3.15, CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-146493
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci i due esempi di import-as nella Python REPL, quindi esamina le due regole corrispondenti in Grammar/python.gram intorno alle righe 1435 e 1439. Confronta la diagnostica risultante con il comportamento previsto descritto nell’issue; il lavoro è completato quando il caso della virgola mancante riceve un errore di sintassi più chiaro. È già indicato un PR collegato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100