LocalToField doesn't validate the offset until get_changes()
メンテナーはふだん 7 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
offset のチェックは rope/refactor/localtofield.py の get_changes() から呼び出される _is_a_method_local() にあります。rope/refactor の他のリファクタリングはこのチェックを __init__ で行っているので、それらと比較してください。issue の再現スニペットを実行し、エラーが遅れて発生することを確認してください。モジュールレベルの変数に対してコンストラクタが RefactoringError を送出し、既存の localtofield テストモジュールのテストがそれをカバーしていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Most refactorings check their offset in the constructor and raise RefactoringError straight away: Rename, create_inline(), MethodObject, IntroduceParameter and UseFunction all do. LocalToField only stores its arguments, so the check happens in get_changes().
Editor integrations build the refactoring object to decide whether to offer it in a menu, and only compute the changes when the user picks it. With LocalToField that shortcut doesn't work: building the object always succeeds, so "Convert local variable to field" is offered everywhere. pylsp-rope offers it this way.
To Reproduce
import pathlib
import tempfile
from rope.base.project import Project
from rope.refactor.localtofield import LocalToField
root = pathlib.Path(tempfile.mkdtemp())
(root / "m.py").write_text("x = 1\n")
project = Project(str(root), ropefolder=None)
refactoring = LocalToField(project, project.get_resource("m.py"), 0)
print("constructor accepted a module-level variable")
refactoring.get_changes()
Output on master (46ebf37), Python 3.13:
constructor accepted a module-level variable
rope.base.exceptions.RefactoringError: Convert local variable to field should be performed on a local variable of a method.
Expected behaviour
The constructor raises the RefactoringError. Moving the _is_a_method_local() check from get_changes() into __init__() would do it, and the check is cheap. I can send a PR with a test if that's acceptable.
Editor information
- Python 3.13
- Rope master 46ebf37 (also 1.14.0)
- Context: rope-language-server issue #19
- 主要言語
- Python
- スター
- 2.2k
- フォーク
- 197
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python-rope/rope のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
python-rope/rope#926 ·
メンテナーはふだん 7 日以内に返信
-
simplify.real_code blanks t-strings, so renames inside them edit the wrong offset対応中かも @sean0407 が 9 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
python-rope/rope#913 ·
メンテナーはふだん 7 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
python-rope/rope#925 ·
メンテナーはふだん 7 日以内に返信
-
Extract method/variable and introduce parameter don't check whether the new name is already in useオープン
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
python-rope/rope#924 ·
メンテナーはふだん 7 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
python-rope/rope#923 ·
メンテナーはふだん 7 日以内に返信
python-rope/rope の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
elviskahoro/sdk-python-attio#144 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
RenyiELBO raises TypeError when model has no sample sites対応中かも @alibb007 が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
[Bug]: Four evaluation scripts unpack init_memmachine_params's five return values into three namesオープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
MemMachine/MemMachine#1911 ·
メンテナーはふだん 3 日以内に返信