From 3820af2f1b3da36717b825b3a081a057e947903b Mon Sep 17 00:00:00 2001 From: InSync Date: Wed, 8 Jan 2025 22:04:08 +0700 Subject: [PATCH] [`pycodestyle`] Avoid false positives related to type aliases (`E252`) (#15356) --- .../resources/test/fixtures/pycodestyle/E25.py | 12 ++++++++++++ .../src/rules/pycodestyle/rules/logical_lines/mod.rs | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E25.py b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E25.py index 5ce8b9cfaa170..7ac031c924c27 100644 --- a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E25.py +++ b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E25.py @@ -79,3 +79,15 @@ def pep_696_good_method[A = int, B: object = str, C:object = memoryview](self): # https://github.com/astral-sh/ruff/issues/15202 type Coro[T: object = Any] = Coroutine[None, None, T] + + +# https://github.com/astral-sh/ruff/issues/15339 +type A = Annotated[ + str, Foo(lorem='ipsum') +] +type B = Annotated[ + int, lambda a=1: ... +] +type C = Annotated[ + int, lambda a: ..., lambda a=1: ... +] diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/mod.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/mod.rs index 9c4e1c0e58b45..167c3456df6aa 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/mod.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/mod.rs @@ -531,7 +531,7 @@ impl DefinitionState { Self::NotInDefinition => return, }; match token_kind { - TokenKind::Lpar if type_params_state_mut.before_type_params() => { + TokenKind::Lpar | TokenKind::Equal if type_params_state_mut.before_type_params() => { *type_params_state_mut = TypeParamsState::TypeParamsEnded; } TokenKind::Lsqb => match type_params_state_mut {