rope icon indicating copy to clipboard operation
rope copied to clipboard

Extracting generator comprehension may produce invalid code

Open lieryan opened this issue 4 years ago • 0 comments

Describe the bug

Extracting generator comprehension may produce invalid code after extraction.

To Reproduce Steps to reproduce the behavior:

  1. Code before refactoring:
foo = sum(x for x in y)
  1. Extract x for x in y, without selecting the outer parentheses

  2. Expected code after extract variable refactoring:

extracted = (x for x in y)
foo = sum(extracted)

or after extract method refactoring:

foo = sum(extracted())
def extracted():
    return (x for x in y)
  1. Instead, we currently produce invalid code when extracting local variable:
extracted = x for x in y
foo = sum(extracted)
  1. And "Unhandled exception in Pymode: invalid syntax (, line 2)" when extracting method"
  • [ ] fix extract variable
  • [ ] fix extract method

lieryan avatar Sep 26 '21 08:09 lieryan