Skip to content

[ruff] Add fix for none-not-at-end-of-union (RUF036) #22829

Open
anishgirianish wants to merge 2 commits intoastral-sh:mainfrom
anishgirianish:feat/ruf036-autofix
Open

[ruff] Add fix for none-not-at-end-of-union (RUF036) #22829
anishgirianish wants to merge 2 commits intoastral-sh:mainfrom
anishgirianish:feat/ruf036-autofix

Conversation

@anishgirianish
Copy link
Contributor

Summary

Adds an autofix for RUF036 that moves None to the end of union type annotations.

Closes #15136

The fix:

  • Preserves the union style (PEP 604 | vs typing.Union)
  • Preserves duplicate None values instead of deduplicating
  • Skips nested unions to avoid flattening (e.g., None | Union[int, str])
  • Marked unsafe when comments are present in the annotation

Test Plan

cargo nextest run -p ruff_linter - added test cases for nested unions, comments,
default arguments, and mixed styles.

@anishgirianish anishgirianish changed the title [ruff] Add fix for none-not-at-end-of-union (RUF036) [ruff] Add fix for none-not-at-end-of-union (RUF036) Jan 24, 2026
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.

Feature request: Autofix for none-not-at-end-of-union (RUF036)

1 participant