Skip to content

MAINT Enable ruff UP (pyupgrade) rules and fix all violations#1389

Merged
romanlutz merged 1 commit intoAzure:mainfrom
romanlutz:romanlutz/ruff_up
Feb 25, 2026
Merged

MAINT Enable ruff UP (pyupgrade) rules and fix all violations#1389
romanlutz merged 1 commit intoAzure:mainfrom
romanlutz:romanlutz/ruff_up

Conversation

@romanlutz
Copy link
Contributor

@romanlutz romanlutz commented Feb 23, 2026

Enable ruff UP (pyupgrade) rules to modernize deprecated typing imports across the codebase (245 files, ~1175 lines changed).

Enabled rules

  • UP — pyupgrade rules added to ruff select

Ignored rules

  • UP007 — Keeps Union[X, Y] syntax (does not convert to X | Y)
  • UP045 — Keeps Optional[X] syntax (does not convert to X | None)

What changed

Modernizes deprecated typing imports to their built-in equivalents:

  • typing.List → list
  • typing.Dict → dict
  • typing.Tuple → tuple
  • typing.Set → set
  • typing.Type → type
  • typing.FrozenSet → frozenset
  • typing.Sequence / typing.MutableSequence → collections.abc.Sequence / collections.abc.MutableSequence

Removes the now-unused deprecated imports from typing via the existing F401 rule.

Optional[X] and Union[X, Y] syntax is intentionally preserved per team preference.

Tests and Documentation

All unit tests pass. No documentation changes needed.

@hannahwestra25
Copy link
Contributor

what is the rationale for moving to implicit optional ?
looking at this:
image
from https://peps.python.org/pep-0484/#union-types

it seems like we shouldn't do this by default and should use https://docs.astral.sh/ruff/rules/implicit-optional/

@hannahwestra25 hannahwestra25 self-assigned this Feb 24, 2026
@romanlutz
Copy link
Contributor Author

what is the rationale for moving to implicit optional ? looking at this: image from https://peps.python.org/pep-0484/#union-types

it seems like we shouldn't do this by default and should use https://docs.astral.sh/ruff/rules/implicit-optional/

Yes, we're getting rid of implicit optional. But instead of Optional[T] ruff prefers T | None which is available from python 3.10 onwards. Does that make sense?

Modernize deprecated typing imports (List->list, Dict->dict, Tuple->tuple,
Set->set, Type->type, FrozenSet->frozenset, Sequence/MutableSequence from
collections.abc). Ignore UP007 (Union syntax) and UP045 (Optional syntax)
to keep existing Optional[X] and Union[X, Y] patterns.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz romanlutz merged commit ac61249 into Azure:main Feb 25, 2026
32 checks passed
@romanlutz romanlutz deleted the romanlutz/ruff_up branch February 25, 2026 13:50
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.

2 participants