Skip to content

Parse strategies

Maturity labels

  • Now: Stable and supported in current releases.
  • Preview: Usable today, but behavior and APIs may evolve.
  • Planned: Not yet implemented.

Note

Status: Now

Parse, don't validate in practice

Let built-in coercion handle straightforward cases

>>> import omnipy as om
>>> om.Model[list[int]](['1', 2, 3.0])

Add custom normalization with _parse_data

>>> import omnipy as om
>>> class IntListFromAnything(om.Model[list[int]]):
...     @classmethod
...     def _parse_data(cls, data):
...         if isinstance(data, tuple):
...             data = list(data)
...         return data
>>> IntListFromAnything(('1', 2, 3.0))

Guidance

  • Normalize obvious ambiguities (whitespace, separators).
  • Do not silently guess semantics you cannot justify.