Factor out logic to generate ModuleNotFoundError in importlib?
まだ誰も着手していません。
評価
調査の方向性
まず、_find_and_load_unlocked エントリポイントと、既存の _ERR_MSG および ModuleNotFoundError の構築箇所を特定します。その構築を _get_module_not_found_error(name) に切り出し、spec が見つからないパスでの直接的な構築を置き換え、結果として得られるエラーが引き続きモジュール名を保持し、monkey patching に適したままであることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Feature or enhancement
PEP 534 discusses improving error messages for standard library modules. We like to do this in Pyodide because some stdlib modules either are removed or are not included by default but can be installed. If someone tries to import these modules, we want to print some extra info about why the import is failing.
The following patch is a simple change that makes it easy to monkey patch _get_module_not_found_error to improve the ModuleNotFound errors:
+def _get_module_not_found_error(name):
+ return ModuleNotFoundError(_ERR_MSG.format(name), name=name)
+
def _find_and_load_unlocked(name, import_):
path = None
parent = name.rpartition('.')[0]
@@ -1001,7 +1004,7 @@ def _find_and_load_unlocked(name, import_):
raise ModuleNotFoundError(msg, name=name) from None
spec = _find_spec(name, path)
if spec is None:
- raise ModuleNotFoundError(_ERR_MSG.format(name), name=name)
+ raise _get_module_not_found_error(name)
else:
module = _load_unlocked(spec)
if parent:
In Pyodide since we are fairly tightly coupled to the Python version we would be okay with risking the possibility that this gets rearranged in the future.
Pitch
It would be nice to apply this patch. See the Pyodide PR: https://github.com/pyodide/pyodide/pull/3263
Previous discussion
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
PolicyEngine/policyengine-us#9559 ·
-
priority: p3
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
googleapis/librarian#7636 ·
-
from:qa priority:P2 reliability tech-debt
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
spec-kitty/spec-kitty#4874 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100