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

Extracting generator comprehension may produce invalid code #411

Closed
2 tasks
lieryan opened this issue Sep 26, 2021 · 0 comments · Fixed by #505
Closed
2 tasks

Extracting generator comprehension may produce invalid code #411

lieryan opened this issue Sep 26, 2021 · 0 comments · Fixed by #505
Labels
affected-version:0.20 bug Unexpected or incorrect user-visible behavior good first issue
Milestone

Comments

@lieryan
Copy link
Member

lieryan commented Sep 26, 2021

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 lieryan added bug Unexpected or incorrect user-visible behavior good first issue affected-version:0.20 labels Sep 26, 2021
@lieryan lieryan added this to the 0.22.x milestone Sep 28, 2021
@lieryan lieryan modified the milestones: 0.22.x, 0.23.0 Nov 22, 2021
@lieryan lieryan modified the milestones: 0.23.0, 0.24.0 Feb 27, 2022
@lieryan lieryan modified the milestones: 1.1.0, 1.2.0 May 20, 2022
@lieryan lieryan modified the milestones: 1.2.0, 1.3.0 Jun 17, 2022
@lieryan lieryan modified the milestones: 1.3.0, 1.4.0 Jul 12, 2022
lieryan added a commit that referenced this issue Sep 27, 2022
Extracting generator comprehension without selecting the surrounding
parentheses may produce invalid code. This commit adds surrounding
parentheses when it detects that the selected code is a bare generator
comprehension.
lieryan added a commit that referenced this issue Sep 27, 2022
Extracting generator comprehension without selecting the surrounding
parentheses may produce invalid code. This commit adds surrounding
parentheses when it detects that the selected code is a bare generator
comprehension.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected-version:0.20 bug Unexpected or incorrect user-visible behavior good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant