Keep from xx import yy style when moving

Đang mở
#694 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 7 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
22/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
tooling

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
2.2k
Fork
197
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python-rope/rope

Tất cả issue của python-rope/rope

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.