Skip to content

🧪 test: add test for non-Name annotated assignment targets#8

Merged
bashandbone merged 3 commits intomainfrom
fix/add-annotated-assign-test-12845267801571331684
Mar 13, 2026
Merged

🧪 test: add test for non-Name annotated assignment targets#8
bashandbone merged 3 commits intomainfrom
fix/add-annotated-assign-test-12845267801571331684

Conversation

@bashandbone
Copy link
Contributor

🎯 What: The testing gap addressed is the missing edge case in the AST parser for annotated assignments (ast.AnnAssign) when the target is an attribute (ast.Attribute) rather than a simple name (ast.Name). Feeding code like self.x: int = 1 into the parser triggers this logic.

📊 Coverage: The scenario of an annotated assignment target that is not a plain name (e.g., self.x: int = 1) is now fully tested and verified to correctly return no symbols.

Result: Increased test coverage and assurance that complex annotated assignments will not crash the AST parser or result in erroneously extracted exportable symbols. The test explicitly verifies that the correct branch is taken and handled gracefully.


PR created automatically by Jules for task 12845267801571331684 started by @bashandbone

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>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 13, 2026 02:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds coverage for an AST parsing edge case around annotated assignments with non-ast.Name targets, and updates a real-file fixture to better represent pre-/post-Python 3.12 type alias styles used by the parser tests.

Changes:

  • Add a unit test asserting that ast.AnnAssign with an attribute target (e.g., self.x: int = 1) yields no extracted symbols.
  • Update the sample_type_aliases.py fixture to use pre-3.12 TypeAlias-annotated assignments for the “pre-3.12” section.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/test_ast_parser.py Adds a new edge-case test for annotated assignments with attribute targets.
tests/fixtures/sample_type_aliases.py Adjusts the “pre-3.12” type alias fixtures to use TypeAlias annotations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 22 to +26
# 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
Comment on lines 22 to +31
# 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]
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>
from typing import TypeAlias


FilePath: TypeAlias = str | Path
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…331684

Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
@bashandbone bashandbone merged commit 572d237 into main Mar 13, 2026
5 of 9 checks passed
@bashandbone bashandbone deleted the fix/add-annotated-assign-test-12845267801571331684 branch March 13, 2026 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants