Skip to content

Commit 19a4bea

Browse files
authored
[flake8-pyi] Rename PYI033 to legacy-type-comment (#26131)
## Summary Rename PYI033 from `type-comment-in-stub` to `legacy-type-comment`, including the internal rule, module, and preview-helper identifiers. The new name reflects that the rule also runs on Python files in preview mode, rather than implying that it only applies to stub files.
1 parent 1d9866c commit 19a4bea

9 files changed

Lines changed: 21 additions & 17 deletions

File tree

‎AGENTS.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@ CARGO_PROFILE_DEV_OPT_LEVEL=1 INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFI
5555
MDTEST_TEST_FILTER="<filter>" CARGO_PROFILE_DEV_OPT_LEVEL=1 INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic --test mdtest -- <path/to/mdtest_file.md>
5656
```
5757

58+
### Snapshot updates
59+
5860
After running the tests, always review the contents of any snapshots that have been added or updated.
5961

6062
When running tests with `INSTA_FORCE_PASS=1`, check for `.pending-snap` files if any affected tests use inline snapshots.
6163

64+
Never edit snapshot files or inline snapshot bodies manually. Regenerate them by running the relevant tests with the snapshot-update environment variables documented above, then review the generated diff.
65+
6266
## Running Clippy
6367

6468
```sh

‎crates/ruff/tests/cli/lint.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4236,7 +4236,7 @@ fn preview_default_rules() -> Result<()> {
42364236
str-or-repr-defined-in-stub (PYI029),
42374237
unnecessary-literal-union (PYI030),
42384238
any-eq-ne-annotation (PYI032),
4239-
type-comment-in-stub (PYI033),
4239+
legacy-type-comment (PYI033),
42404240
non-self-return-type (PYI034),
42414241
unassigned-special-variable-in-stub (PYI035),
42424242
bad-exit-annotation (PYI036),

‎crates/ruff_linter/src/checkers/tokens.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ pub(crate) fn check_tokens(
157157
pyupgrade::rules::extraneous_parentheses(context, tokens, locator);
158158
}
159159

160-
if context.is_rule_enabled(Rule::TypeCommentInStub) {
161-
flake8_pyi::rules::type_comment_in_stub(context, locator, comment_ranges, source_type);
160+
if context.is_rule_enabled(Rule::LegacyTypeComment) {
161+
flake8_pyi::rules::legacy_type_comment(context, locator, comment_ranges, source_type);
162162
}
163163

164164
if context.any_rule_enabled(&[

‎crates/ruff_linter/src/codes.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
822822
(Flake8Pyi, "029") => rules::flake8_pyi::rules::StrOrReprDefinedInStub,
823823
(Flake8Pyi, "030") => rules::flake8_pyi::rules::UnnecessaryLiteralUnion,
824824
(Flake8Pyi, "032") => rules::flake8_pyi::rules::AnyEqNeAnnotation,
825-
(Flake8Pyi, "033") => rules::flake8_pyi::rules::TypeCommentInStub,
825+
(Flake8Pyi, "033") => rules::flake8_pyi::rules::LegacyTypeComment,
826826
(Flake8Pyi, "034") => rules::flake8_pyi::rules::NonSelfReturnType,
827827
(Flake8Pyi, "035") => rules::flake8_pyi::rules::UnassignedSpecialVariableInStub,
828828
(Flake8Pyi, "036") => rules::flake8_pyi::rules::BadExitAnnotation,

‎crates/ruff_linter/src/preview.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub(crate) const fn is_bad_version_info_in_non_stub_enabled(settings: &LinterSet
5454
}
5555

5656
// https://github.com/astral-sh/ruff/issues/4460
57-
pub(crate) const fn is_type_comment_in_non_stub_enabled(settings: &LinterSettings) -> bool {
57+
pub(crate) const fn is_legacy_type_comment_in_non_stub_enabled(settings: &LinterSettings) -> bool {
5858
settings.preview.is_enabled()
5959
}
6060

‎crates/ruff_linter/src/registry.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl Rule {
301301
| Rule::TooManyBlankLines
302302
| Rule::TooManyNewlinesAtEndOfFile
303303
| Rule::TrailingCommaOnBareTuple
304-
| Rule::TypeCommentInStub
304+
| Rule::LegacyTypeComment
305305
| Rule::UselessSemicolon
306306
| Rule::UTF8EncodingDeclaration => LintSource::Tokens,
307307
Rule::IOError => LintSource::Io,

‎crates/ruff_linter/src/rules/flake8_pyi/mod.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ mod tests {
9191
#[test_case(Rule::TSuffixedTypeAlias, Path::new("PYI043.pyi"))]
9292
#[test_case(Rule::TypeAliasWithoutAnnotation, Path::new("PYI026.py"))]
9393
#[test_case(Rule::TypeAliasWithoutAnnotation, Path::new("PYI026.pyi"))]
94-
#[test_case(Rule::TypeCommentInStub, Path::new("PYI033.py"))]
95-
#[test_case(Rule::TypeCommentInStub, Path::new("PYI033.pyi"))]
94+
#[test_case(Rule::LegacyTypeComment, Path::new("PYI033.py"))]
95+
#[test_case(Rule::LegacyTypeComment, Path::new("PYI033.pyi"))]
9696
#[test_case(Rule::TypedArgumentDefaultInStub, Path::new("PYI011.py"))]
9797
#[test_case(Rule::TypedArgumentDefaultInStub, Path::new("PYI011.pyi"))]
9898
#[test_case(Rule::UnaliasedCollectionsAbcSetImport, Path::new("PYI025_1.py"))]
@@ -146,7 +146,7 @@ mod tests {
146146
#[test_case(Rule::RedundantNumericUnion, Path::new("PYI041_2.py"))]
147147
#[test_case(Rule::RedundantNumericUnion, Path::new("PYI041_3.py"))]
148148
#[test_case(Rule::RedundantNumericUnion, Path::new("PYI041_4.py"))]
149-
#[test_case(Rule::TypeCommentInStub, Path::new("PYI033.py"))]
149+
#[test_case(Rule::LegacyTypeComment, Path::new("PYI033.py"))]
150150
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
151151
let snapshot = format!(
152152
"preview_{}_{}",

crates/ruff_linter/src/rules/flake8_pyi/rules/type_comment_in_stub.rs renamed to crates/ruff_linter/src/rules/flake8_pyi/rules/legacy_type_comment.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use ruff_python_trivia::CommentRanges;
99
use crate::Locator;
1010
use crate::Violation;
1111
use crate::checkers::ast::LintContext;
12-
use crate::preview::is_type_comment_in_non_stub_enabled;
12+
use crate::preview::is_legacy_type_comment_in_non_stub_enabled;
1313

1414
/// ## What it does
1515
/// Checks for the use of type comments (e.g., `x = 1 # type: int`).
@@ -36,31 +36,31 @@ use crate::preview::is_type_comment_in_non_stub_enabled;
3636
/// ```
3737
#[derive(ViolationMetadata)]
3838
#[violation_metadata(stable_since = "v0.0.254")]
39-
pub(crate) struct TypeCommentInStub;
39+
pub(crate) struct LegacyTypeComment;
4040

41-
impl Violation for TypeCommentInStub {
41+
impl Violation for LegacyTypeComment {
4242
#[derive_message_formats]
4343
fn message(&self) -> String {
4444
"Don't use type comments".to_string()
4545
}
4646
}
4747

4848
/// PYI033
49-
pub(crate) fn type_comment_in_stub(
49+
pub(crate) fn legacy_type_comment(
5050
context: &LintContext,
5151
locator: &Locator,
5252
comment_ranges: &CommentRanges,
5353
source_type: PySourceType,
5454
) {
55-
if !source_type.is_stub() && !is_type_comment_in_non_stub_enabled(context.settings()) {
55+
if !source_type.is_stub() && !is_legacy_type_comment_in_non_stub_enabled(context.settings()) {
5656
return;
5757
}
5858

5959
for range in comment_ranges {
6060
let comment = locator.slice(range);
6161

6262
if TYPE_COMMENT_REGEX.is_match(comment) && !TYPE_IGNORE_REGEX.is_match(comment) {
63-
context.report_diagnostic(TypeCommentInStub, range);
63+
context.report_diagnostic(LegacyTypeComment, range);
6464
}
6565
}
6666
}

‎crates/ruff_linter/src/rules/flake8_pyi/rules/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub(crate) use exit_annotations::*;
2525
pub(crate) use future_annotations_in_stub::*;
2626
pub(crate) use generic_not_last_base_class::*;
2727
pub(crate) use iter_method_return_iterable::*;
28+
pub(crate) use legacy_type_comment::*;
2829
pub(crate) use no_return_argument_annotation::*;
2930
pub(crate) use non_empty_stub_body::*;
3031
pub(crate) use non_self_return_type::*;
@@ -43,7 +44,6 @@ pub(crate) use str_or_repr_defined_in_stub::*;
4344
pub(crate) use string_or_bytes_too_long::*;
4445
pub(crate) use stub_body_multiple_statements::*;
4546
pub(crate) use type_alias_naming::*;
46-
pub(crate) use type_comment_in_stub::*;
4747
pub(crate) use unaliased_collections_abc_set_import::*;
4848
pub(crate) use unnecessary_literal_union::*;
4949
pub(crate) use unnecessary_type_union::*;
@@ -68,6 +68,7 @@ mod exit_annotations;
6868
mod future_annotations_in_stub;
6969
mod generic_not_last_base_class;
7070
mod iter_method_return_iterable;
71+
mod legacy_type_comment;
7172
mod no_return_argument_annotation;
7273
mod non_empty_stub_body;
7374
mod non_self_return_type;
@@ -86,7 +87,6 @@ mod str_or_repr_defined_in_stub;
8687
mod string_or_bytes_too_long;
8788
mod stub_body_multiple_statements;
8889
mod type_alias_naming;
89-
mod type_comment_in_stub;
9090
mod unaliased_collections_abc_set_import;
9191
mod unnecessary_literal_union;
9292
mod unnecessary_type_union;

0 commit comments

Comments
 (0)