refactor(testing): drop duplicate abstract fork name declaration - #913
Merged
tcoratger merged 3 commits intoJun 10, 2026
Merged
Conversation
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>
The fork name was declared abstract twice: once on the metaclass so its own methods could call cls.name(), and once as the classmethod that concrete forks override. Type the metaclass methods' cls as the fork class instead. The repr and ordering methods then resolve name through the single classmethod, so the metaclass-level declaration is no longer needed. The classmethod remains the one source of truth and still enforces that every concrete fork implements name. Repr, ordering, and abstractness are unchanged, and emitted vectors keep the same network field. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…k-name-declaration # Conflicts: # packages/testing/src/consensus_testing/test_fixtures/networking_codec.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The fork
name()was declared abstract twice inforks/base.py:BaseForkMeta), so its own__repr__could callcls.name(), and@classmethod @abstractmethodonBaseForkthat concrete forks override.The metaclass declaration was not dead, though — removing it outright makes the type checker fail on
cls.name()inside__repr__(Self has no attribute name). It existed only so the metaclass methods could resolvename.What this does
Types the metaclass methods'
clsparameter astype[BaseFork](which it always is —BaseForkMetais only everBaseFork's metaclass). The__repr__and__le__methods then resolvenamethrough the single classmethod, so the metaclass-level abstract declaration can be dropped.The
@classmethod @abstractmethod name()onBaseForkremains the one source of truth and still enforces that every concrete fork implements it.Behavior preserved
Testing
just checkpasses (lint, format, ty, codespell, mdformat).name,repr, ordering, and ABC enforcement are unchanged.networkfield is still"Lstar".🤖 Generated with Claude Code