Skip to content

validate parameters through pydantic

Peter Lünenschloß requested to merge pydantic into develop

adresses #457

  • Merge Request changes the argument typechecking procedure for all the SaQC Methods in the funcs module to be handled by pydantic

  • this means that appropriate checks now are solely indicated by the parameters Typehints and in-function-body checks were removed

  • Pydantic will throw an error when a paremeter value fails the assigned class instance test or violates the value constraints imposed. Error Messages contain details like function name, parameter name nd detailed cause of exception.

  • There are several new Type "Aggregates" added to the saqc.lib.types module.

    • The Types Float and Int are typehint-restricted classes, that allow for shorthand denotion of Constrained Types in the Form of: Float > 2 , Int <= 7 | Float >= 1, Int > 0 | OffsetString ... - and so on.
    • The other new types, like OffsetString, SaQCField, ArrayLike, ... are (Generic) Aggregates or Functionally defined Types or mixtures of those, that repeatedly occure in the Test Functions
  • I didnt use Alias definitions, but real class instances instead, because Sphinx.autodocs Alias Handling is buggy to say the least and the only way i figured to prevent the signtures in the documentation from getting messed up and the constraints from not being displayed, was to rely on the Typehints class already having the approriate repr() for being displayed as the typehint in the doc

  • Am a little new to the typing/abc/meta rabbit hole and it was quite confusing: i might have done some things sub optimal and am definetly happy for improvement suggestions and advice on the handling of the whole class/inheritance thing

Thats how constraint types are represented in the documentation now:

Bildschirmfoto_von_2024-11-23_20-31-37

Edited by Peter Lünenschloß

Merge request reports

Loading