Skip to content
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

Avoid overlapping regions when extract similar=True #246

Merged
merged 1 commit into from Jun 25, 2018

Conversation

brendanator
Copy link
Contributor

If similar regions are found during extract method that overlap, the refactored code is invalid

For example, if the first two lines of func are extracted

def func(p):
    a = p
    b = a
    c = b
    d = c
    return d

the following is produced

def func(p):
    b = new_func(p)c = new_func(a)d = new_func(b)
    b = new_func(p)
    d = new_func(b)
    return d
def new_func(p):
    a = p
    b = a
    return b

With this PR a correct refactoring is performed

def func(p):
    b = new_func(p)
    d = new_func(b)
    return d
def new_func(p):
    a = p
    b = a
    return b

@soupytwist
Copy link
Contributor

Looks good, thank you for debugging + fixing this!

@soupytwist soupytwist added the bug Unexpected or incorrect user-visible behavior label Jun 25, 2018
@soupytwist soupytwist merged commit 97b9421 into python-rope:master Jun 25, 2018
@brendanator brendanator deleted the extract-overlapping branch July 5, 2018 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect user-visible behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants