feat: from import (PR2: from x import y [as w])#134
Open
ryuichi1208 wants to merge 3 commits into
Open
Conversation
Add KW_FROM keyword and parse from-imports into Import.names as a list of (name, alias) pairs. Sema resolution lands in the next commit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Build a per-module from_env (local name -> (module, name)) and resolve unqualified calls against it. Detect collisions with local functions, builtins, and duplicate imported names. irgen is unchanged: resolution flows through call_resolution as before. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
examples/import_from.rw exercises `from x import a, b as c` against the existing import_basic_lib. Add it to the e2e parametrize list plus a lexer test for the `from` keyword. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4 tasks
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 の PR2 / 全3 PR。
from x import y [as w]で選択シンボルを取り込み、修飾なしで呼べるようにする。from math_lib import add→add(...)と修飾なし呼び出しfrom math_lib import add, mul as m→ 複数取り込み・as別名ベースは PR1 (#133)。 PR1 がマージされてから本 PR をマージする想定(base を
feat/namespaced-importsにしている)。設計の要点
KW_FROMを追加。parser はfrom IDENT import IDENT [as IDENT] {, ...}をImport.names((name, alias)のリスト)に詰める。from_env: Dict[localname, (module, name)]を構築し、修飾なし呼び出しをfrom_env優先で解決。衝突(ローカル関数 / ビルトイン / 重複)を import 位置で検出。call_resolutionを通り、同じrw_user_<module>_<name>シンボルを呼ぶだけ。変更ファイル
rwc/lexer.pyKW_FROMrwc/parser.py_parse_from_import/_parse_import_namerwc/sema.py_build_from_env、_resolve_user_funcの修飾なし経路examples/import_from.rw,tests/*Test plan
uv run pytest -q、PR1 比 +10)import_from.rw(from import_basic_lib import add, mul as times)を実行し5\n20\nrw_user_import_basic_lib_add等に解決されることを確認Non-Goals
ワイルドカード
from x import */ 再エクスポート / 型エイリアスの import。import x as mは PR3。🤖 Generated with Claude Code