fastparse and native parser assign different line numbers to nested subscripts in multi-line type annotations
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report
For a multi-line type annotation containing an error in a nested subscript, fastparse and nativeparse assign different line numbers to the resulting UnboundType. fastparse uses the outermost annotation line (self.line fixed at TypeConverter construction); nativeparse uses the actual per-node source line. Downstream, type-arg / arity errors reported against that node show up on different lines depending on which parser was used.
I ran into this as # type: ignore comments in serial mode became unused-ignore when trying parallel mode due to the line number difference.
To Reproduce
producer.py:
def foo() -> dict[
str,
dict[int, int, int],
]:
return {}
mypy.ini:
[mypy]
python_version = 3.12
rm -rf .mypy_cache && mypy --num-workers=0 producer.py # fastparse
rm -rf .mypy_cache && mypy --num-workers=0 --native-parser producer.py # nativeparse, no workers
Expected Behavior
Both parsers should agree on the reported line — either both line 1 (outer annotation) or both line 3 (inner offending node).
Actual Behavior
| invocation | reported line |
|---|---|
--num-workers=0 (fastparse, no native-parser) |
1 (outer dict[) |
--num-workers=0 --native-parser |
3 (inner dict[int, int, int]) |
Same error in both: "dict" expects 2 type arguments, but 3 given [type-arg].
Bisection notes:
- The divergence requires the error-bearing node to be a nested sub-expression. Top-level multi-line wrong-arity (
x: (\n dict[str, str, str]\n ) = {}) reports line 1 in both parsers. - Single-line wrong-arity has nothing to diverge on; both parsers agree.
Your Environment
- Mypy version used: 2.1.0 (PyPI). Also reproduces on current master (
2.2.0+dev.e53693be05a2). - Mypy command-line flags:
--native-parser selects the inner-line behavior; default (--num-workers=0, no--native-parser`) selects the outer-line behavior. - Mypy configuration:
python_version = 3.12. - Python version used: 3.12.13
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
Inizia con i percorsi fastparse e nativeparse intorno a TypeConverter, usando l’esempio producer.py e i comandi mypy forniti per riprodurre le righe differenti. Traccia come le righe sorgente dei subscript annidati diventano posizioni UnboundType, quindi verifica che entrambi i parser segnalino la stessa riga e che l’errore type-arg e il comportamento di type-ignore rimangano coerenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers, devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100