Skip to content

refactor(testing): drop duplicate abstract fork name declaration - #913

Merged
tcoratger merged 3 commits into
leanEthereum:mainfrom
tcoratger:refactor/dedupe-fork-name-declaration
Jun 10, 2026
Merged

refactor(testing): drop duplicate abstract fork name declaration#913
tcoratger merged 3 commits into
leanEthereum:mainfrom
tcoratger:refactor/dedupe-fork-name-declaration

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

Motivation

The fork name() was declared abstract twice in forks/base.py:

  • on the metaclass (BaseForkMeta), so its own __repr__ could call cls.name(), and
  • as the @classmethod @abstractmethod on BaseFork that 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 resolve name.

What this does

Types the metaclass methods' cls parameter as type[BaseFork] (which it always is — BaseForkMeta is only ever BaseFork's metaclass). The __repr__ and __le__ methods then resolve name through the single classmethod, so the metaclass-level abstract declaration can be dropped.

The @classmethod @abstractmethod name() on BaseFork remains the one source of truth and still enforces that every concrete fork implements it.

Behavior preserved

Lstar.name() = Lstar
repr(Lstar)  = Lstar
Lstar <= Lstar = True
BaseFork()            -> abstract (cannot instantiate)
class F(BaseFork): pass; F()  -> abstract (name still required)

Testing

  • just check passes (lint, format, ty, codespell, mdformat).
  • Runtime checks confirm name, repr, ordering, and ABC enforcement are unchanged.
  • Fill smoke: the emitted network field is still "Lstar".

🤖 Generated with Claude Code

tcoratger and others added 3 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>
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
@tcoratger
tcoratger merged commit 2cf265f into leanEthereum:main Jun 10, 2026
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