Stub generation adds too many explicit re-exports
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
mypy stubgen re-exports more names than needed (despite --export-less). It seems that imports that are only used in function parameter type annotations (see FirstErrorType below) are always re-exported and imports from 'if TYPE_CHECKING' clauses (see SecondErrorType below) as well.
To Reproduce
# example.py
from typing import TYPE_CHECKING
from b import FirstErrorType, WorkingType
if TYPE_CHECKING:
from c import SecondErrorType
def foobar(one: FirstErrorType, two: "SecondErrorType") -> None:
pass
def spamandeggs() -> WorkingType:
return WorkingType()
Expected Behavior
Nether FirstErrorType nor SecondErrorType should be re-exported according to the documentation of the --export-less switch, which states
only export imported names that are not referenced in the module that contains the import.
Actual Behavior
the output of stubgen --export-less example.py
# example.pyi
from b import FirstErrorType as FirstErrorType, WorkingType
from c import SecondErrorType as SecondErrorType
def foobar(one: FirstErrorType, two: SecondErrorType) -> None: ...
def spamandeggs() -> WorkingType: ...
Your Environment
- Mypy version used: 1.13.0
- Mypy command-line flags: stubgen --export-less
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.10
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 il problema con l'esempio example.py mostrato ed esegui stubgen --export-less, quindi esamina il file example.pyi generato. Traccia la gestione da parte di stubgen degli import usati solo per le annotazioni e degli import sotto TYPE_CHECKING; il lavoro è completato quando FirstErrorType e SecondErrorType non sono riesportazioni esplicite, mentre WorkingType rimane esportato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100