Skip to content

fix: handle annotated assignments (AnnAssign) in migration files#5

Merged
stephen-kintsugi merged 2 commits into
mainfrom
bug/4-support-annassign
Mar 2, 2026
Merged

fix: handle annotated assignments (AnnAssign) in migration files#5
stephen-kintsugi merged 2 commits into
mainfrom
bug/4-support-annassign

Conversation

@stephen-kintsugi
Copy link
Copy Markdown
Collaborator

@stephen-kintsugi stephen-kintsugi commented Mar 2, 2026

Summary

  • Handle ast.AnnAssign nodes alongside ast.Assign in extract_revision_info so migrations using revision: str = '...' (newer Alembic default) are parsed correctly
  • Add test coverage for annotated standard, first, and merge migrations

Fixes #4

Tests

35/35 passing, including 3 new tests for annotated assignment parsing.

Summary by CodeRabbit

  • Chores

    • Bumped version to 0.3.2
  • New Features

    • Added support for annotated assignments in Alembic migration file processing, enabling compatibility with modern Python syntax conventions
  • Tests

    • Added comprehensive test coverage for annotated migration metadata handling across multiple migration scenarios

Newer Alembic versions generate `revision: str = '...'` instead of
`revision = '...'`. The AST parser only handled Assign nodes, silently
skipping every migration that used the annotated form.

Closes #4
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 2, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2ff2940 and e80ff29.

📒 Files selected for processing (4)
  • pyproject.toml
  • squawk_alembic/__init__.py
  • squawk_alembic/hook.py
  • tests/test_revision_info.py

Walkthrough

This PR adds support for parsing annotated assignments (PEP 526 type annotations) in Alembic migration files, allowing the hook to handle both revision = '...' and revision: str = '...' syntax. Version bumped to 0.3.2 with comprehensive test coverage for the new functionality.

Changes

Cohort / File(s) Summary
Version Updates
pyproject.toml, squawk_alembic/__init__.py
Patch version bump from 0.3.1 to 0.3.2.
AST Parsing Enhancement
squawk_alembic/hook.py
Added support for ast.AnnAssign nodes alongside ast.Assign in extract_revision_info to handle annotated revision variable declarations. Validates target is a Name and value exists for AnnAssign; existing Assign logic preserved.
Test Coverage
tests/test_revision_info.py
Added three new tests validating annotated assignment handling: standard annotated revision with Union typing, first migration with None down_revision, and merge revision scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bug/4-support-annassign

Comment @coderabbitai help to get the list of available commands and usage tips.

@stephen-kintsugi stephen-kintsugi force-pushed the bug/4-support-annassign branch from 1e79fda to e80ff29 Compare March 2, 2026 22:11
@stephen-kintsugi stephen-kintsugi merged commit a29baae into main Mar 2, 2026
7 checks passed
@stephen-kintsugi stephen-kintsugi deleted the bug/4-support-annassign branch March 2, 2026 22:13
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.

hook silently skips migrations with annotated assignments (AnnAssign)

2 participants