rope icon indicating copy to clipboard operation
rope copied to clipboard

Restructuring fails with if statement

Open Epikem opened this issue 7 years ago • 1 comments

I'm trying to substitute a variable with restructuring but it failed with following error. environment : visual studio, pypy2 5.9.0, rope 0.10.7

[dddd.py]

project = Project(os.path.join(defs.IO_Dir, 'test1'))
mod1 = project.get_resource('mod1.py')
from rope.refactor import restructure
#pattern = '${pow_func}(${param1}, ${param2})'
#goal = '${param1} ** ${param2}'
#args = {'pow_func': 'name=mod1.pow'}
pattern = '${Debug}'
goal = 'True'
args = {'Debug': 'name=mod1.lalala'}
restructuring = restructure.Restructure(project, pattern, goal, args)
k = restructuring.get_changes(resources=[mod1] )
project.do(k)

[mod1.py] Try 1

lalala = 44453
if(lalala == False):
	lalala = 409024
	pass

[mod1.py] Try 2

lalala = 44453
if(lalala == False):
	lalala = 409024
	pass
elif(534 == lalala):
	pass

[mod1.py] Try 3

lalala = 44453
if(lalala == False):
	lalala = 409024
	pass
elif(534 == lalala):
	pass
else:
	lalala = 55223
	pass

Try 1 succeeded but try 2 and 3 fails with following error each: Try 2 : rope.refactor.patchedast.MismatchedTokenError: Token at (7, 6) cannot be matched Try 3 : rope.refactor.patchedast.MismatchedTokenError: Token at (7, 5) cannot be matched

Epikem avatar Nov 04 '17 02:11 Epikem

Thank you for reporting and including good tests cases to reproduce it.

soupytwist avatar Nov 06 '17 17:11 soupytwist