Skip to content

Fix extraction of nested named expressions - #876

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

yangfan-yf-yf wants to merge 2 commits 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.

@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.34%. Comparing base (2bd17a8) to head (c2047fb).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #876   +/-   ##
=======================================
  Coverage   95.34%   95.34%           
=======================================
  Files         134      134           
  Lines       26819    26819           
=======================================
  Hits        25570    25570           
  Misses       1249     1249           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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