Keep from xx import yy style when moving

未關閉
#694 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 7 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
22/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
python
領域
tooling

研究方向

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

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python-rope/rope 的其他 Issue

查看 python-rope/rope 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。