From 58fd90a632d683e6611f3463f771ac93fd2c229f Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 20 Nov 2023 12:23:54 +0000 Subject: [PATCH] Avoid N806 errors for type alias statements --- .../resources/test/fixtures/pep8_naming/N806.py | 2 ++ crates/ruff_linter/src/rules/pep8_naming/helpers.rs | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/pep8_naming/N806.py b/crates/ruff_linter/resources/test/fixtures/pep8_naming/N806.py index 0a9a95954c73c..e509a27e12bc5 100644 --- a/crates/ruff_linter/resources/test/fixtures/pep8_naming/N806.py +++ b/crates/ruff_linter/resources/test/fixtures/pep8_naming/N806.py @@ -25,6 +25,8 @@ def assign(): IntOrStr: TypeAlias = int | str + type MyInt = int + def aug_assign(rank, world_size): global CURRENT_PORT diff --git a/crates/ruff_linter/src/rules/pep8_naming/helpers.rs b/crates/ruff_linter/src/rules/pep8_naming/helpers.rs index 6d09971253201..24fcb6d92dbb3 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/helpers.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/helpers.rs @@ -63,10 +63,13 @@ pub(super) fn is_type_var_assignment(stmt: &Stmt, semantic: &SemanticModel) -> b /// Returns `true` if the statement is an assignment to a `TypeAlias`. pub(super) fn is_type_alias_assignment(stmt: &Stmt, semantic: &SemanticModel) -> bool { - let Stmt::AnnAssign(ast::StmtAnnAssign { annotation, .. }) = stmt else { - return false; - }; - semantic.match_typing_expr(annotation, "TypeAlias") + match stmt { + Stmt::AnnAssign(ast::StmtAnnAssign { annotation, .. }) => { + semantic.match_typing_expr(annotation, "TypeAlias") + } + Stmt::TypeAlias(_) => true, + _ => false, + } } pub(super) fn is_typed_dict_class(arguments: Option<&Arguments>, semantic: &SemanticModel) -> bool {