Skip to content

Enabled the flake8-type-checking plugin rules for the ruff linter#5029

Open
JayeshHire wants to merge 3 commits intoopen-telemetry:mainfrom
JayeshHire:TCH-rule
Open

Enabled the flake8-type-checking plugin rules for the ruff linter#5029
JayeshHire wants to merge 3 commits intoopen-telemetry:mainfrom
JayeshHire:TCH-rule

Conversation

@JayeshHire
Copy link
Copy Markdown

@JayeshHire JayeshHire commented Apr 1, 2026

Description

I have enabled the flake8-type-checking plugin rules for ruff linter in this PR. This plugin contains a set of rules which will check for those imports which are only used for type annotations and are not imported inside the type-checking block. Imports which are only used for type annotation are of no use at runtime and they'll just consume unnecessary memory. Hence, they should be imported inside the type-checking block.

TC001-3: Imports used for type annotations should be imported inside the type-checking block
TC004: Imports used at runtime should not be imported inside the type-checking block
TC005: Type checking block should not be empty
TC006: Type expressions in typing.cast() should be quoted so that they can be ignored at runtime
TC010: Type unions such as X | Y should be inside quoted blocks.

Ignored rules:

TC007: This rule enforces to add quotes to the data type of TypeAlias variables. The static checkers cannot determine the behavior of the runtime typing libraries. This makes this rule unsafe. Hence, ignored here.
TC008: This rule is unstable and in preview.

Finally, I have changed all the files which were violating the flake8-type-checking rules.

Contributes to #4227

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A

uv run ruff check
All checks passed!

  • Test B

Ran the unit tests for API and SDK. Also ran the precommit actions.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated

@JayeshHire JayeshHire requested a review from a team as a code owner April 1, 2026 17:46
@tammy-baylis-swi tammy-baylis-swi moved this to Ready for review in Python PR digest Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

2 participants