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

Reuse of variable in comprehensions confuses method extraction #315

Closed
chrisbarber opened this issue Oct 26, 2020 · 0 comments · Fixed by #395
Closed

Reuse of variable in comprehensions confuses method extraction #315

chrisbarber opened this issue Oct 26, 2020 · 0 comments · Fixed by #395

Comments

@chrisbarber
Copy link

Extract method for the a = and b = lines individually.

Actual

def f():
    y = [1,2,3,4]

    a = sum((x for x in y))

    b = sum([x for x in y])

    print(a, b)

f() 
def f():
    y = [1,2,3,4]

    x, a = _a(y)

    b = _b(x, y)

    print(a, b)

def _b(x, y):
    b = sum([x for x in y])
    return b

def _a(y):
    a = sum((x for x in y))
    return x, a

f()

Expected

def f():
    y = [1,2,3,4]

    a = sum((x1 for x1 in y))

    b = sum([x2 for x2 in y])

    print(a, b)

f() 
def f():
    y = [1,2,3,4]

    a = _a(y)

    b = _b(y)

    print(a, b)

def _b(y):
    b = sum([x2 for x2 in y])
    return b

def _a(y):
    a = sum((x1 for x1 in y))
    return a

f()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants