Skip to content

Fix extraction of nested named expressions - #876

Open
yangfan-yf-yf wants to merge 1 commit into
python-rope:masterfrom
yangfan-yf-yf:fix-extract-nested-named-expression
Open

yangfan-yf-yf wants to merge 1 commit into
python-rope:masterfrom
yangfan-yf-yf:fix-extract-nested-named-expression

Conversation

@yangfan-yf-yf

Copy link
Copy Markdown
Contributor

Description

Extracting i := a == (c := 5) can generate if i, c := new_func(a):, which is invalid Python. I fixed the named-expression visitor to traverse the assigned value so the existing extraction check detects the nested assignment and raises RefactoringError.

I updated the regression test that previously expected the invalid output. Single named-expression extraction and extraction of complete statements remain supported by the existing tests.

Fixes #871

Validation

  • Windows, Python 3.12.3: python -m pytest -q — 2116 passed, 12 skipped, 5 xfailed.
  • Extraction and use-function tests: 180 passed, 1 skipped, 1 xfailed.
  • The corrected regression fails on the unpatched code (RefactoringError not raised).
  • All five configured pre-commit checks passed for the changed files.

The first full run had two autoimport failures because my temporary directory was under an underscore-prefixed path. I reproduced both on unmodified master and reran the full suite successfully with a different temporary directory.

Checklist

  • I have updated the regression test for the reported behavior.
  • I have updated CHANGELOG.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extracting a function from walrus assignment with an internal walrus assignment produces invalid code

1 participant