TypeChecker.lookup_qualified can't find names in submodules
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Parti dall’implementazione collegata di lookup_qualified in mypy/checker.py e traccia come ctx.api.named_generic_type risolve i nomi puntati. Riproduci il caso di sott modulo annidato descritto nel report con un plugin, quindi verifica che nomi qualificati come foo.bar.baz.Qux possano essere trovati senza dipendere dall’interfaccia TypeChecker.modules non documentata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Report
Writing my first mypy plugin, I tried to use the exposed interface ctx.api.named_generic_type to look up a type in my package by name, which is in a submodule like:
ctx.api.named_generic_type('foo.bar.baz.Qux', [])
In this case ctx is a FunctionContext but it applies to most (all?) relevant plugin hook contexts.
The name is not found because foo.bar.baz is a submodule.
To Reproduce
See above.
Expected Behavior
Since this is the only public API for looking up named types, it should be possible--especially for plugins that could be intended for some specific third-party libraries--to be able to look into nested module namespaces.
Actual Behavior
The current implementation uses lookup_qualified which as written assumes that only the first component of a dotted name is necessarily a module name. It then looks into the symbol table for that module to find subsequent name components. This works fine for type lookups like typing.Type but not for other cases, as there is no guarantee that a submodule name is found in its parent module's namespace.
Probably should check the symbol table first, and if not found try the next component as a module name.
To work around this, have to dig into the undocumented TypeChecker.modules to find the required type.
Your Environment
- Mypy version used: 1.1.1
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.9
- 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
- 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.
Altre issue di python/mypy
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug topic-configuration topic-error-reporting
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
zostera/django-bootstrap4#894 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
use-agent-os/agent-os#3276 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#117848 ·