Skip to content

feat!: infer union tags from literal annotations - #303

Merged
dbrattli merged 1 commit into
mainfrom
feat/infer-union-tags
Nov 12, 2026
Merged

dbrattli merged 1 commit into
mainfrom
feat/infer-union-tags

Conversation

@dbrattli

Copy link
Copy Markdown
Owner

Case declarations currently repeat the discriminator string in both the Literal annotation and tag(). Derive the runtime default from the annotation so declarations become tag: Literal["customer_id"] = tag().

Inference runs when the class is declared, including Python 3.14 deferred annotations, without adding work to instance construction. Update built-in cases, documentation, and typing contracts, and document single-case domain types.

Breaking change: tag("name") is no longer accepted. Replace it with tag() and keep the single-string Literal annotation. Tags remain excluded from constructors and positional patterns.

Verification: uv run pytest -q and uv run pre-commit run --all-files.

@dbrattli
dbrattli merged commit c6df7a3 into main Nov 12, 2026
7 checks passed
@dbrattli
dbrattli deleted the feat/infer-union-tags branch November 12, 2026 01:05
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.

1 participant