Skip to content

Avoid syntax errors for type variables with starred constraints (UP040, UP046, UP047, RUF053) - #28362

Merged
ntBre merged 7 commits into
astral-sh:mainfrom
LckyLke:fix/pep695-starred-constraints
Oct 16, 2026
Merged

ntBre merged 7 commits into
astral-sh:mainfrom
LckyLke:fix/pep695-starred-constraints

Conversation

@LckyLke

@LckyLke LckyLke commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

fixes #26954.

Adds the missing tuple comma so starred contraints produce valid pep 695 fixes. Existing single element constraint tuples also keep their comma.

Tests cover aliases, classes and function type paramters across all four rules. All 2828 linter tests, clippy and hooks passed. checked the fixed code on python 3.12 and 3.14.

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre September 6, 2026 17:24
}

if non_default_follows_default(&vars) {
if non_default_follows_default(&vars) || vars.iter().any(TypeVar::has_starred_constraint) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to have the same issue identified in #28232 (comment).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes you're right that (*constraints,) is valid. I fixed the shared formatter, removed the checks that skipped starred contraints, and added regression tests for all four rules. These fixes were also verifed on python 3.12 and 3.14.

@LckyLke
LckyLke force-pushed the fix/pep695-starred-constraints branch from 7737ca4 to f8695b7 Compare September 9, 2026 07:26
@LckyLke LckyLke changed the title Skip PEP 695 fixes for TypeVars with starred constraints (UP040, UP046, UP047, RUF053) fix starred constraints in pep 695 conversions (up040, up046, up047, ruf053) Sep 9, 2026
@ntBre ntBre changed the title fix starred constraints in pep 695 conversions (up040, up046, up047, ruf053) Avoid syntax errors for type variables with starred constraints (UP040, UP046, UP047, RUF053) Oct 16, 2026
@ntBre ntBre added bug An issue describing something that isn't working, or a PR that fixes a bug fixes Related to suggested fixes for violations labels Oct 16, 2026

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I took care of the merge conflicts, trimmed the tests a bit, and also refactored the case with more than one element, but the fix here looked good.

@astral-sh-bot

astral-sh-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre
ntBre enabled auto-merge (squash) October 16, 2026 17:02
@ntBre
ntBre merged commit c4d0597 into astral-sh:main Oct 16, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fixes for UP046 and UP047 introduce syntax errors for starred constraints

2 participants