Skip to content

refactor(poseidon): use native Pydantic field constraints#815

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:poseidon-native-field-constraints
Jun 1, 2026
Merged

refactor(poseidon): use native Pydantic field constraints#815
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:poseidon-native-field-constraints

Conversation

@tcoratger
Copy link
Copy Markdown
Collaborator

Summary

Tidies up PoseidonParams to follow the codebase's existing conventions and lean on Pydantic's native field constraints instead of a custom validator.

  • Move the Field(description=...) text into attribute docstrings, matching the docstring-after-field convention used elsewhere (e.g. the Poseidon class right below it).
  • Replace the rounds_f even-count field_validator with the native multiple_of=2 constraint. The validation constraints (gt, ge, min_length) are preserved on the fields.
  • Preserve the "why it must be even" rationale in the field docstring.
  • Drop the now-unused field_validator import.

Notes

The native multiple_of error message ("Input should be a multiple of 2") is less domain-specific than the old custom message. The test was updated accordingly. All other validators in the codebase were reviewed and genuinely can't move to native constraints — they're either input coercion (mode="before"), dynamic per-subclass bounds (cls.LENGTH/cls.LIMIT), or cross-field relationships.

Testing

  • just check passes (lint, format, typecheck, spell, mdformat).
  • uv run pytest tests/lean_spec/spec/crypto/test_poseidon.py — 18 passed.

🤖 Generated with Claude Code

Move PoseidonParams field descriptions into attribute docstrings,
matching the convention used elsewhere in the codebase.

Replace the rounds_f even-count field validator with the native
multiple_of=2 constraint, preserving the rationale in the field
docstring and dropping the now-unused field_validator import.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tcoratger tcoratger merged commit 8ba33be into leanEthereum:main Jun 1, 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