Skip to content

v0.4.2

Choose a tag to compare

@aaronstevenwhite aaronstevenwhite released this 05 May 18:45
· 15 commits to main since this release
da606ef

Fixed

  • @dx.validates is no longer a silent no-op. The metaclass walks target.__mro__ for methods carrying the __didactic_validator__ marker and stores them on the class as __field_validators__; Model.__init__ and Model.with_(...) invoke them in the right order: dx.field(converter=...) first, then mode="before" validators on the raw value, then the encoder, then mode="after" validators on the canonical decoded value (re-encoded if the validator returned a different value). Validators may raise ValueError / raise TypeError to reject the input; failures surface as ValidationError entries with type="validator_error" and loc=(field_name,). Instance, @classmethod, and @staticmethod shapes all work. Subclasses inherit a parent's validators; a subclass override that re-applies @validates replaces the inherited method, and a subclass that shadows the method without @validates deliberately disables validation for that field. (#17)

Changed

  • docs/guide/validators.md was rewritten to document the raise ValueError / return-value-replaces-stored-value contract (the previous draft described a return bool shape that the runtime never implemented), and to cover mode="before", multi-field validators, multiple-validator chaining, inheritance semantics, and the three method shapes.

Full changelog: https://github.com/panproto/didactic/blob/main/CHANGELOG.md