Skip to content

Enable ruff pyupgrade (UP) lint rules#4940

Open
toroleapinc wants to merge 2 commits intoopen-telemetry:mainfrom
toroleapinc:feat/issue-4227-ruff-UP-rule
Open

Enable ruff pyupgrade (UP) lint rules#4940
toroleapinc wants to merge 2 commits intoopen-telemetry:mainfrom
toroleapinc:feat/issue-4227-ruff-UP-rule

Conversation

@toroleapinc
Copy link

Summary

Enable a subset of safe pyupgrade (UP) ruff rules that are compatible with the Python 3.8 target version:

  • UP011: Remove unnecessary parentheses from @lru_cache()
  • UP015: Remove redundant open() mode arguments
  • UP032: Replace .format() calls with f-strings
  • UP034: Remove extraneous parentheses
  • UP037: Remove unnecessary quoted annotations (in files with from __future__ import annotations)

All 42 violations were auto-fixed by ruff check --fix.

Not included (unsafe for py38 target): UP006, UP007, UP031, UP045 which require Python 3.9+/3.10+ syntax.

Part of #4227

@toroleapinc toroleapinc requested a review from a team as a code owner February 27, 2026 16:09
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 27, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@xrmx xrmx moved this to Easy to review / merge / close in Python PR digest Mar 2, 2026
@xrmx xrmx added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Mar 2, 2026
@xrmx
Copy link
Contributor

xrmx commented Mar 2, 2026

@toroleapinc thanks for the PR we can accept contributions only if you sign the CLA

Enable a subset of pyupgrade rules that are safe for the Python 3.8
target version:
- UP011: lru-cache-without-parameters
- UP015: redundant-open-modes
- UP032: f-string (replaces .format() calls)
- UP034: extraneous-parentheses
- UP037: quoted-annotation (removes unnecessary string quotes)

All 42 violations were auto-fixed by ruff.

Part of open-telemetry#4227

Signed-off-by: edvatar <88481784+toroleapinc@users.noreply.github.com>
@toroleapinc toroleapinc force-pushed the feat/issue-4227-ruff-UP-rule branch from 40895e2 to a79066b Compare March 3, 2026 05:33
Copy link
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍🏻

@tammy-baylis-swi
Copy link
Contributor

Thanks @toroleapinc ! Please do these and push the fixes:

  • tox -e precommit
  • tox -e lint-opentelemetry-sdk

@lzchen
Copy link
Contributor

lzchen commented Mar 11, 2026

@toroleapinc

Thanks for the contribution! Just curious, what was the thought-process behind choosing these specific ruff rules or is this arbitrary?

@toroleapinc
Copy link
Author

@lzchen These weren't arbitrary — I picked the rules that had the most existing violations in the codebase to get the biggest cleanup in one pass:

  • UP032 (f-string): most of the diff, converting .format() calls to f-strings for readability
  • UP037 (quoted-annotation): removing unnecessary string quotes around forward-ref annotations that are no longer needed
  • UP011 (lru-cache-without-parameters): minor cleanup, @lru_cache()@lru_cache
  • UP015 (redundant-open-modes): dropping explicit "r" mode in open() calls
  • UP034 (extraneous-parentheses): removing redundant parens

I deliberately left out the more disruptive UP rules (like UP007 for X | Y union syntax) since those would require bumping the minimum Python version. Happy to adjust the scope if you'd prefer a different subset.

@toroleapinc
Copy link
Author

@tammy-baylis-swi Ran both — tox -e precommit caught some whitespace and formatting issues, pushed the fixes. tox -e lint-opentelemetry-sdk passes (10/10 rating) but has a pre-existing E1101 on measurement_consumer.py:67 that's unrelated to this PR.

@lzchen
Copy link
Contributor

lzchen commented Mar 12, 2026

@toroleapinc

Happy to adjust the scope if you'd prefer a different subset.

No need, the separation makes sense. As long as we have a documented set of supported/supported SGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog PRs that do not require a CHANGELOG.md entry

Projects

Status: Easy to review / merge / close

Development

Successfully merging this pull request may close these issues.

5 participants