Keep from xx import yy style when moving
Les mainteneurs répondent en général sous 7 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 22/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 2.2k
- Forks
- 197
- Merge moyen
- 2 j 13 h
- PR mergées (30 j)
- 5
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python-rope/rope
-
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
python-rope/rope#927 ·
Les mainteneurs répondent en général sous 7 jours
-
Extract raises IndexError or ModuleSyntaxError instead of RefactoringError for an empty or whitespace-only regionPeut-être pris @aliassar l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
python-rope/rope#926 ·
Les mainteneurs répondent en général sous 7 jours
-
simplify.real_code blanks t-strings, so renames inside them edit the wrong offsetPeut-être pris @sean0407 l’a pris il y a 10 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
python-rope/rope#913 ·
Les mainteneurs répondent en général sous 7 jours
-
Difficulté 4/5 3-5 jours Accessibilité débutants 30/100
python-rope/rope#925 ·
Les mainteneurs répondent en général sous 7 jours
-
Extract method/variable and introduce parameter don't check whether the new name is already in useOuverte
Difficulté 3/5 1-2 jours Accessibilité débutants 62/100
python-rope/rope#924 ·
Les mainteneurs répondent en général sous 7 jours
Toutes les issues de python-rope/rope
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
unionai-oss/pandera#2640 ·
Les mainteneurs répondent en général sous 2 jours
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
JdeRobot/RoboticsInfrastructure#843 ·
Les mainteneurs répondent en général sous 1 jour
-
automated endpoint-dead needs-curation
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
almanac-data/climate-almanac#122 ·
Les mainteneurs répondent en général sous 1 jour
-
area:harness enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
evarness-ai/iris-harness#420 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
suitenumerique/find#206 ·
Les mainteneurs répondent en général sous 2 jours