-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MoveModule creates new top-level imports #731
Comments
A test case for python-rope#731
My understanding is that in this particular case, This may be an additional issue overlapping with the original one actually: I can change Currently
|
I tried extending test_is_import_statement with: def test_is_import_statement(self):
code, annotations = self._annotated_code(annotated_code=dedent("""\
import a.b.c.d
++++++++
from a.b import c
import a.b.c.d as d
+++++++++++++
from a.b import c as e
from a.b import (
abc
)
result = a.b.c.d.f()
def import_later():
import lazy
+++++
""")) And the following output, which AFAIU confirms that
Did I get the annotation syntax right? |
H'm, is it intentional that you begin at the leftmost character of the line and then try to go further left? |
Hi @SomeoneSerge, thanks for writing this issue and creating the PR. I'm currently travelling on vacation, so my availability to look into rope issues and review PRs will be limited until December. So don't worry, but I hadn't forgotten about this 🙂, but I won't be actioning the PR until I'm back. |
I think I just encountered the @lieryan any pointers as to where to begin? |
Describe the bug
When
MoveModule
encounters an import statement inside a function (thus, evaluated at some unknown point later and maybe never), and the import statement concerns the module being moved, the calculated changes include both a modification of the original import statement and an extraneous import statement at the top of the file. This changes the order of imports and, in sufficiently cursed code-bases, may even result in a circular import.Basically, the issue is that
MoveModule
appears to consider imports to be side effect-free, which sometimes they aren't.The extra import is being added here:
rope/rope/refactor/move.py
Lines 594 to 596 in 25586a6
rope/rope/refactor/move.py
Lines 769 to 773 in 25586a6
To Reproduce
Steps to reproduce the behavior:
Rename (move)
b
intoprefix.b
.Reproducible example
Editor information (please complete the following information):
Additional context
Context: trying to use Rope for some automation in https://github.com/SomeoneSerge/pkgs/blob/master/python-packages/by-name/pr/prefix-python-modules/prefix_python_modules.py
The text was updated successfully, but these errors were encountered: