Identical, anonymous intersection types causes incompatible import [assignment] error when imported via *
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
If you import * from two modules that infer an identical intersection type, mypy will report an error along the lines of
Incompatible import of "<intersection>" (imported name has type "type[a.<intersection>]", local name has type "type[b.<intersection>]") [assignment]
To Reproduce
This repro requires multiple files. They are delineated by comments.
# shared.py
class Foo: ...
class Bar: ...
# a.py
from shared import Foo, Bar
a_foos: list[Foo]
a_bars = [f for f in a_foos if isinstance(f, Bar)]
# b.py
from shared import Foo, Bar
b_foos: list[Foo]
b_bars = [f for f in b_foos if isinstance(f, Bar)]
# c.py
from a import *
from b import *
The offending mypy invocation is as follows:
$ mypy -m c
Expected Behavior
This should not emit an error because no runtime locals are actually assigned, or at the very least, because the intersections are identical.
Actual Behavior
c.py:2: error: Incompatible import of "<subclass of "Foo" and "Bar">" (imported name has type "type[b.<subclass of "Foo" and "Bar">]", local name has type "type[a.<subclass of "Foo" and "Bar">]") [assignment]
Found 1 error in 1 file (checked 1 source file)
Your Environment
This bug was reproduced in a fresh venv on Debian GNU/Linux 10 (buster):
$ python --version
Python 3.10.13
$ mypy --version
mypy 1.6.0 (compiled: yes)
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
Crea i quattro file mostrati nel report: shared.py, a.py, b.py e c.py, quindi esegui mypy -m c per riprodurre l’errore di importazione incompatibile. Traccia la gestione delle importazioni con asterisco e dei tipi di intersezione anonimi inferiti; il lavoro è completato quando le intersezioni identiche non producono più un errore e il repro continua a superare correttamente il controllo dei tipi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100