Skip to content

Recognize match pattern captures as assignments - #865

Open
yangfan-yf-yf wants to merge 2 commits into
python-rope:masterfrom
yangfan-yf-yf:fix/match-case-bindings-861
Open

Recognize match pattern captures as assignments#865
yangfan-yf-yf wants to merge 2 commits into
python-rope:masterfrom
yangfan-yf-yf:fix/match-case-bindings-861

Conversation

@yangfan-yf-yf

Copy link
Copy Markdown
Contributor

Description

Pattern capture names on MatchAs, MatchStar, and MatchMapping are string fields, so the scope visitor did not register them as assignments. Rename consequently rejected those names as unresolved. Inline could also replace a capture with a value pattern, changing program semantics.

This registers the three capture forms in their enclosing scope, returns a conservative unknown inference result for pattern assignments, and rejects inline whenever the selected name has a pattern-capture assignment. Rename now updates both capture definitions and references.

Fixes #861

Checklist

  • I have added tests that prove the fix is effective
  • I have updated CHANGELOG.md

Validation

  • Full suite: 2121 passed, 12 skipped, 5 xfailed
  • Relevant selection: 442 passed, 10 skipped
  • All configured pre-commit checks for the changed Python files pass
  • git diff origin/master...HEAD --check passes

@yangfan-yf-yf
yangfan-yf-yf marked this pull request as ready for review August 26, 2026 11:03
@lieryan lieryan added this to the 1.16.0 milestone Sep 7, 2026
@yangfan-yf-yf

Copy link
Copy Markdown
Contributor Author

I merged the current master into 48c33d9 to resolve the conflict. Only the changelog entries conflicted; both the pattern-capture entry and the new is_dir() entry are retained. The pattern-capture implementation is unchanged by the merge.

Validation on Windows / Python 3.12:

  • Full suite: 2121 passed, 12 skipped, 5 xfailed, 1 failed.
  • The failure is ropetest/contrib/autoimporttest.py::test_search_submodule. It also fails in a separate checkout of unmodified master at f005ac7 with the same assertion: searching for mod1 from the installed external_fixturepkg returns no matches.
  • All configured pre-commit hooks for the PR's Python files pass, and the diff has no whitespace errors.

The branch update is pushed for the upstream checks to run.

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.

Rename and inline refactor did not recognize match-cases statements as variable assignment

2 participants