Upgrade ruff and rename ruleset: TCH → TC#1626
Conversation
TCH → TCTCH → TC
| 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] |
There was a problem hiding this comment.
This is enforced by new rules? Seems like a weird one to pick on since str is built-in.
There was a problem hiding this comment.
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 intyping.TYPE_CHECKINGblocks. This can lead to a visual inconsistency across differentcast()calls, where some type expressions are quoted but others are not. By enabling this rule, you ensure that all type expressions passed tocast()are quoted, enforcing stylistic consistency across all of yourcast()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-checkingis 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 inflake8), 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.
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`
for more information, see https://pre-commit.ci
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-checkingcategory fromTCHtoTC. This matches changes that were made in the originalflake8-type-checkingplugin 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:
TC006in0.8.1is too broad astral-sh/ruff#14676Test plan
Just CI.
The issues with Python 3.8 seem unrelated.