TypeChecker.lookup_qualified can't find names in submodules
まだ誰も着手していません。
評価
調査の方向性
mypy/checker.py にあるリンク先の lookup_qualified の実装から始め、ctx.api.named_generic_type がドット区切りの名前をどのように解決するかを追跡してください。レポートにあるネストしたサブモジュールのケースを plugin で再現し、そのうえで、文書化されていない TypeChecker.modules インターフェースに依存せずに、foo.bar.baz.Qux のような修飾名を見つけられることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/mypy のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
bug topic-configuration topic-error-reporting
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
zostera/django-bootstrap4#894 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
use-agent-os/agent-os#3276 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NousResearch/hermes-agent#117848 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
zilliztech/memsearch#759 ·