Skip to content

feat(spec-tool): enforce @final on leaf dataclasses#2965

Merged
SamWilsn merged 1 commit into
ethereum:forks/amsterdamfrom
danceratopz:lint-final
Jun 9, 2026
Merged

feat(spec-tool): enforce @final on leaf dataclasses#2965
SamWilsn merged 1 commit into
ethereum:forks/amsterdamfrom
danceratopz:lint-final

Conversation

@danceratopz

@danceratopz danceratopz commented Jun 9, 2026

Copy link
Copy Markdown
Member

🗒️ Description

Follow-up to #2934. Add a FinalDecoratorHygiene rule to ethereum-spec-lint that enforces @final on leaf dataclasses across the specification.

PR #2934 added @final to leaf dataclasses (@dataclass and @slotted_freezable classes that are never subclassed) so mypyc can bypass the vtable for method calls and property accessors. This rule keeps that coverage from drifting as new forks are copied forward or new dataclasses are added.

The rule:

  • Flags any leaf dataclass that is missing @final. Classes that are subclassed are skipped because they are not leaves, as are non-dataclass types such as enums, protocols, exceptions, and constant namespaces.
  • Scans the whole specification once: every fork's modules plus the shared modules such as ethereum.state and ethereum.trace, including each package's __init__.py.
  • Is registered in vulture_whitelist.py, since lints are discovered dynamically.

Note: Because the check is a whole-specification invariant, it runs once at the first fork position, so diagnostics are grouped under the earliest fork's header (frontier). Each message names the full module path, for example ethereum.forks.amsterdam.state_tracker, so the location is unambiguous.

Example output:
image

🔗 Related Issues or PRs

Related to #2934.

✅ Checklist

  • All: Ran fast static checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:
    just static
  • All: PR title adheres to the repo standard - it will be used as the squash commit message and should start type(scope):.
  • All: Considered updating the online docs in the ./docs/ directory.
  • All: Set appropriate labels for the changes (only maintainers can apply labels).

Cute Animal Picture

image

Add a `FinalDecoratorHygiene` lint rule that flags any leaf dataclass (a
`@dataclass` or `@slotted_freezable` class never used as a base) that is
missing `@final`. Marking leaf dataclasses `@final` lets `mypyc` bypass
the vtable for method calls and property accessors.

The rule scans the whole specification once at the first fork position:
every fork's modules plus the shared modules such as `ethereum.state` and
`ethereum.trace`, including each package's `__init__.py`. Register the rule
in `vulture_whitelist.py` since lints are discovered dynamically.
@danceratopz danceratopz added A-spec-tool Area: Specification Tooling—Tools for the Ethereum specification (eg. `src/ethereum_spec_tools/*`) C-feat Category: an improvement or new feature labels Jun 9, 2026
@danceratopz danceratopz requested a review from SamWilsn June 9, 2026 08:45
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.50%. Comparing base (9c2813e) to head (417f48b).

Additional details and impacted files
@@                 Coverage Diff                 @@
##           forks/amsterdam    #2965      +/-   ##
===================================================
+ Coverage            90.06%   90.50%   +0.43%     
===================================================
  Files                  488      535      +47     
  Lines                29562    32700    +3138     
  Branches              2686     3011     +325     
===================================================
+ Hits                 26626    29595    +2969     
- Misses                2457     2588     +131     
- Partials               479      517      +38     
Flag Coverage Δ
unittests 90.50% <ø> (+0.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SamWilsn SamWilsn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

@SamWilsn SamWilsn merged commit b40f815 into ethereum:forks/amsterdam Jun 9, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-spec-tool Area: Specification Tooling—Tools for the Ethereum specification (eg. `src/ethereum_spec_tools/*`) C-feat Category: an improvement or new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants