feat: import as (PR3: import x as m)#135
Open
ryuichi1208 wants to merge 4 commits into
Open
Conversation
Allow an optional `as IDENT` on plain imports, filling Import.alias. Sema resolution lands in the next commit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the visible-imports set with import_env (visible qualifier -> real module), so `import x as m` makes `m.f()` resolve to module x. The bare module name is no longer a valid qualifier once aliased. Detect duplicate qualifiers. irgen is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
examples/import_as.rw exercises `import x as m` with `m.f()` calls. Add it to the e2e parametrize list. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
pyproject で宣言済みの dev 依存 (black/ruff/mypy) と プロジェクトバージョン 0.0.5 を uv.lock に反映する同期コミット。 機能変更なし。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Python 風 import の PR3 / 全3 PR(最終)。
import x as mで別名を付け、m.f()と修飾呼び出しできるようにする。import math_lib as m→m.add(...)math_lib.は無効(Python と同じ)ベースは PR2 (#134)。 マージ順序は PR1 → PR2 → PR3。
設計の要点
[as IDENT]を許しImport.aliasを埋めるだけ。_visible_imports(実モジュール名の集合)をimport_env: Dict[visible_name, real_module]に置換。import x→{x: x}、import x as m→{m: x}。修飾呼び出しq.f()はqをimport_envで実モジュールに変換してから解決。rw_user_<module>_<name>を呼ぶだけ(PR1 のcall_resolution経由)。これで Python 風 import の 3 形式(
import x/from x import y/import x as m)が出揃う。変更ファイル
rwc/parser.pyas対応rwc/sema.py_build_import_env、修飾呼び出しの別名解決examples/import_as.rw,tests/*Test plan
uv run pytest -q、PR2 比 +4)import_as.rw(import import_basic_lib as m→m.add/m.mul)を実行し5\n20\nm.add()がrw_user_import_basic_lib_addに解決されることを確認Non-Goals
パッケージ階層 / 再エクスポート / 標準ライブラリ(spec 17 のまま据え置き)。
🤖 Generated with Claude Code