Skip to content

Upgrade ruff and rename ruleset: TCHTC#1626

Merged
dukecat0 merged 5 commits intopypa:mainfrom
DimitriPapadopoulos:TCH
May 5, 2025
Merged

Upgrade ruff and rename ruleset: TCHTC#1626
dukecat0 merged 5 commits intopypa:mainfrom
DimitriPapadopoulos:TCH

Conversation

@DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented May 4, 2025

  • I have added a news fragment under changelog.d/ (if the patch affects the end users)

Summary of changes

Ruff 0.8.0 changes the error codes for the rules in the flake8-type-checking category from TCH to TC. This matches changes that were made in the original flake8-type-checking plugin from which these rules were originally adapted.

https://astral.sh/blog/ruff-v0.8.0#new-error-codes-for-flake8-type-checking-rules

Not sure whether to apply or ignore rule TC006. See discussions here:

Test plan

Just CI.

The issues with Python 3.8 seem unrelated.

@DimitriPapadopoulos DimitriPapadopoulos changed the title Rename ruff ruleset: TCHTC Upgrade ruff and rename ruleset: TCHTC May 4, 2025
sys.argv[0] = "pipx"
parser, _ = get_command_parser()
parser.man_short_description = cast(str, parser.description).splitlines()[1] # type: ignore[attr-defined]
parser.man_short_description = cast("str", parser.description).splitlines()[1] # type: ignore[attr-defined]
Copy link
Member

@uranusjr uranusjr May 5, 2025

Choose a reason for hiding this comment

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

This is enforced by new rules? Seems like a weird one to pick on since str is built-in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the result of TC006 kicking in, probably after upgrading ruff.

The purpose of TC006 is primarily to enforce a consistent style:

This rule helps enforce a consistent style across your codebase.

It's often necessary to quote the first argument passed to cast(), as type expressions can involve forward references, or references to symbols which are only imported in typing.TYPE_CHECKING blocks. This can lead to a visual inconsistency across different cast() calls, where some type expressions are quoted but others are not. By enabling this rule, you ensure that all type expressions passed to cast() are quoted, enforcing stylistic consistency across all of your cast() calls.

So while applying the rule to str might not be a clear improvement, it's part of a plan to enforce consistency. This is an opinionated rule, which is why I asked whether you'd rather enforce or ignore it. From astral-sh/ruff#14676 (comment):

Everyone will have to make their own trade-offs based on their use-cases, flake8-type-checking is definitely one of the more opinionated plugins, so it doesn't come as a surprise to me, that there are some rules or decisions a significant number of people disagree with, but it's also worth recognizing, that you may also find a significant number of people in the opposite camp.

But I can at least tell you that while, when this rule was first introduced in flake8-type-checking, there was one issue opened, that complained about it (mostly due to the churn it caused, since there are no automatic fixes in flake8), there has been no mention of it in the two years since then. So it appears that people are generally happy to either live with the rule in its current state or disable it, we haven't had any requests to change it, or make it more configurable.

DimitriPapadopoulos and others added 5 commits May 5, 2025 23:04
Ruff 0.8.0 changes the error codes for the rules in the flake8-type-checking
category from TCH to TC. This matches changes that were made in the original
flake8-type-checking plugin from which these rules were originally adapted.

https://astral.sh/blog/ruff-v0.8.0#new-error-codes-for-flake8-type-checking-rules
TC006 Add quotes to type expression in `typing.cast()`
PLW1508 Invalid type for environment variable default; expected `str` or `None`
@dukecat0 dukecat0 enabled auto-merge (squash) May 5, 2025 15:04
@dukecat0 dukecat0 disabled auto-merge May 5, 2025 15:33
@dukecat0 dukecat0 merged commit e6ae882 into pypa:main May 5, 2025
10 checks passed
@DimitriPapadopoulos DimitriPapadopoulos deleted the TCH branch May 5, 2025 15:36
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.

3 participants