From e1b9f144a9278175a2f62b7286cb639668045742 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 13 Mar 2026 02:27:28 +0000 Subject: [PATCH 1/2] test: add test for annotated assignment to attribute target Adds a test to `tests/test_ast_parser.py` to ensure that `ASTParser._handle_annotated_assign` correctly ignores annotated assignments when the target is not an `ast.Name` (e.g., `self.x: int = 1`). Also fixes the `sample_type_aliases.py` fixture which had an incorrect syntax for pre-3.12 type aliases. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- tests/fixtures/sample_type_aliases.py | 16 +++++++++------- tests/test_ast_parser.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/fixtures/sample_type_aliases.py b/tests/fixtures/sample_type_aliases.py index 0e1426c..31e6a12 100644 --- a/tests/fixtures/sample_type_aliases.py +++ b/tests/fixtures/sample_type_aliases.py @@ -20,13 +20,15 @@ test_file_path: FilePath | None = None # Pre-3.12 style type aliases (X: TypeAlias = Y) -type FilePath = str | Path -type ModuleName = str -type RulePattern = str -type ExportName = str -type ErrorMessage = str -type ConfigDict = dict[str, str | int | bool | list[str]] -type NamePair = tuple[str, str] +from typing import TypeAlias + +FilePath: TypeAlias = str | Path +ModuleName: TypeAlias = str +RulePattern: TypeAlias = str +ExportName: TypeAlias = str +ErrorMessage: TypeAlias = str +ConfigDict: TypeAlias = dict[str, str | int | bool | list[str]] +NamePair: TypeAlias = tuple[str, str] # Python 3.12+ style type aliases (type X = Y) type FileContent = str diff --git a/tests/test_ast_parser.py b/tests/test_ast_parser.py index 20670c6..41a379b 100644 --- a/tests/test_ast_parser.py +++ b/tests/test_ast_parser.py @@ -172,6 +172,19 @@ def test_annotated_variable(self, parser) -> None: finally: file_path.unlink() + def test_annotated_assignment_attribute_target(self, parser) -> None: + """Ignore annotated assignment to attributes (non-Name targets).""" + content = """ +self.x: int = 1 +""" + file_path = create_temp_file(content) + try: + result = parser.parse_file(file_path, "test.module") + + assert len(result.symbols) == 0 + finally: + file_path.unlink() + def test_regular_variable(self, parser) -> None: """Extract regular variable.""" content = """ From a57abf7549021ab2b8c17e0261978889f21e125e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 13 Mar 2026 02:32:31 +0000 Subject: [PATCH 2/2] test: add test for annotated assignment to attribute target Adds a test to `tests/test_ast_parser.py` to ensure that `ASTParser._handle_annotated_assign` correctly ignores annotated assignments when the target is not an `ast.Name` (e.g., `self.x: int = 1`). Also fixes a CI failure caused by the `sample_type_aliases.py` fixture. The file uses `UP040` (pre-3.12 `TypeAlias` syntax) on purpose to test backward compatibility, but `ruff` was reporting an error for it. We added `# ruff: noqa: UP040` to suppress the linting error for this specific file. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- tests/fixtures/sample_type_aliases.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/fixtures/sample_type_aliases.py b/tests/fixtures/sample_type_aliases.py index 31e6a12..cab5dc6 100644 --- a/tests/fixtures/sample_type_aliases.py +++ b/tests/fixtures/sample_type_aliases.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2026 Knitli Inc. # # SPDX-License-Identifier: MIT OR Apache-2.0 +# ruff: noqa: UP040 """Sample module with type aliases for testing the AST parser. @@ -22,6 +23,7 @@ # Pre-3.12 style type aliases (X: TypeAlias = Y) from typing import TypeAlias + FilePath: TypeAlias = str | Path ModuleName: TypeAlias = str RulePattern: TypeAlias = str