From e67f7f243df91591d33509405b6f20cfa602e97c Mon Sep 17 00:00:00 2001 From: David Salvisberg Date: Wed, 4 Dec 2024 14:16:31 +0100 Subject: [PATCH] [`flake8-type-checking`] Expands TC006 docs to better explain itself (#14749) Closes: #14676 I think the consensus generally was to keep the rule as-is, but expand the docs. ## Summary Expands the docs for TC006 with an explanation for why the type expression is always quoted, including mention of another potential benefit to this style. --- .../rules/runtime_cast_value.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs index 446cf5afd1..27593b6a16 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_cast_value.rs @@ -8,11 +8,22 @@ use crate::checkers::ast::Checker; use crate::rules::flake8_type_checking::helpers::quote_type_expression; /// ## What it does -/// Checks for an unquoted type expression in `typing.cast()` calls. +/// Checks for unquoted type expressions in `typing.cast()` calls. /// /// ## Why is this bad? -/// `typing.cast()` does not do anything at runtime, so the time spent -/// on evaluating the type expression is wasted. +/// 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. +/// +/// In some cases where `cast()` is used in a hot loop, this rule may also +/// help avoid overhead from repeatedly evaluating complex type expressions at +/// runtime. /// /// ## Example /// ```python