Keep from xx import yy style when moving
維護者通常 7 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
The move logic is in rope/refactor/move.py: the reporter's experiment changes _new_import, which builds the import for the destination, and the new_name assignment near line 571. Start by reading how the moved module's old and new names are used there. Their own patch breaks when the source module is nested deeper than one level (for example A.C moved to B.D.C), so a working version must handle that case. Done means a move keeps the from-import style for both shallow and nested modules, with no leftover bare imports. The thread has no maintainer response, so the design should be agreed before writing code.
由索引模型根據 Issue 內容生成。
描述
When I try to use rope as a libaray to move module A.C to B.C, I found that code like "from A.C import foo;foo()" will be changed to "A.C.foo()", which will extremely enlarge my code when foo is in modulde like "from A.C.D.E.G"
I want to keep my origin style like "from B.C import foo;foo()", which only change import statment
After single debug and read the source code, I think the core control of such case may in rope.refactor.move,replace from NormalImport to FromImport may works?
I actually just attempted to make the following modifications :
# in https://github.com/python-rope/rope/blob/master/rope/refactor/move.py#L553
def _new_import(self, dest):
# origin code
# return importutils.NormalImport([(self._new_modname(dest), None)])
# What I changed
return importutils.FromImport(libutils.modname(dest),0, [(self.old_name, None)])
# in https://github.com/python-rope/rope/blob/master/rope/refactor/move.py#L571
# origin code
# new_name = self._new_modname(dest)
# What I changed
new_name = self.old_name
when I run it on my project, it seems work only when src module`s deepth is 1,when src module is like A.C
move will change the code in wrong way like:
a.py
import A.C
move A.C -> B.D.C
a.py
import C
from B.D import C
May I request the project team to include this feature as a new feature in the project? Thank you for your work and effort.
- 主要語言
- Python
- 星號
- 2.2k
- 分支
- 197
- 平均合併
- 2 天 13 小時
- 30 天內合併 PR
- 5
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python-rope/rope 的其他 Issue
-
難度 1/5 1-3 小時 新手友好度 88/100
python-rope/rope#927 ·
維護者通常 7 天內回覆
-
難度 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 於 10 天前認領。 未關閉
難度 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 天內回覆
相似的 Issue
-
Import errors are swallowed: PerthImplicitWatermarker silently becomes None可能已有人在做 @JonRC 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
resemble-ai/Perth#23 ·
-
correction metadata
難度 2/5 1 小時以內 新手友好度 65/100
acl-org/acl-anthology#10753 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
earthtojake/text-to-cad#758 ·
維護者通常 1 天內回覆
-
難度 1/5 1-3 小時 新手友好度 70/100
DataTalksClub/faq#545 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆