Skip to content

refactor(testing): use A | B syntax in discriminated unions - #912

Merged
tcoratger merged 2 commits into
leanEthereum:mainfrom
tcoratger:refactor/pep604-discriminated-unions
Jun 10, 2026
Merged

refactor(testing): use A | B syntax in discriminated unions#912
tcoratger merged 2 commits into
leanEthereum:mainfrom
tcoratger:refactor/pep604-discriminated-unions

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

Motivation

Three discriminated unions still used typing.Union inside Annotated, while the rest of the package uses the PEP 604 A | B | C syntax (e.g. SlotClockOutput = IntervalOutput | SlotOutput | TotalIntervalsOutput). A small consistency gap.

  • test_types/step_types.pyForkChoiceStep, FilledForkChoiceStep
  • test_fixtures/slot_clock.pySlotClockOperation
  • test_fixtures/networking_codec.pyNetworkingCodec

What this does

Switches all three to Annotated[A | B | C, Field(discriminator=...)] and drops the now-unused Union import from each file. Pydantic v2 treats Annotated[A | B, Field(discriminator=...)] identically to the Union form.

Byte-equivalence

Filled the affected suites (fork_choice, networking, slot clock) before and after:

275 passed
diff -rq <golden> <new>  ->  IDENTICAL: no vector churn

Testing

  • just check passes (lint, format, ty, codespell, mdformat); no Union[ remains in the package.
  • All 275 affected vectors are byte-identical to the pre-change output.

🤖 Generated with Claude Code

tcoratger and others added 2 commits June 10, 2026 15:32
Three discriminated unions still used typing.Union inside Annotated, while
the rest of the package uses the PEP 604 A | B | C syntax.

Switch them to A | B | C and drop the now-unused Union import.
Pydantic treats Annotated[A | B, Field(discriminator=...)] identically, so
every emitted vector is byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…criminated-unions

# Conflicts:
#	packages/testing/src/consensus_testing/test_fixtures/networking_codec.py
@tcoratger
tcoratger merged commit b16b31a into leanEthereum:main Jun 10, 2026
12 of 13 checks passed
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