Doby’s ESA Pyxel Logs🌙

✨🦕 Pyxel Contribution: Implementation of check_validity (Issue #988)

Summary:
Implements the new core validation function check_validity for Pyxel, supporting typing.Annotated, Literal, tuples, unions, and annotated-types constraints. This forms the foundation for Pyxel’s future validation and configuration system.

Merge Request:
https://gitlab.com/esa/pyxel/-/merge_requests/1141

Screenshot of the merge request for Issue #988

screenshot

Date: 2025-12-02

✨ Overview

This contribution introduces a brand-new validation mechanism to Pyxel through:

pyxel/util/check_validity.py

The new function ensures that model parameters match the expected types and constraints, raising clear errors when they do not.


🔧 Technical Details

New files added:

  • pyxel/util/check_validity.py
  • tests/util/test_check_validity_basic.py
from typing import Annotated, Literal
from annotated_types import Ge, Gt, Interval

value: Annotated[float, Ge(0.0)]
mode: Literal["auto", "manual"]
coords: tuple[
  Annotated[int, Ge(0)],
  Annotated[int, Ge(0)]
]

🧪 Testing

The test suite validates the behavior described in Issue #988, including correct support for Annotated constraints, Literal values, tuple structures, and Union types.


📁 Branch & File Changes

Branch: issue-988-check-validity

New files:

  • pyxel/util/check_validity.py
  • tests/util/test_check_validity_basic.py

🚀 Future Work

  • Integrate check_validity into ValueDescriptor
  • Validate YAML configuration parameters
  • Expose metadata in Pyxel’s configuration schema
  • Add support for unit-aware constraints
  • Improve user-facing error messages

🌱 Lessons Learned

  • How to build recursive validation using Python’s typing module
  • The importance of aligning tests with issue requirements
  • How to design small, review-friendly merge requests
  • The power of metadata-driven validation systems
  • Growing confidence by contributing foundational code

🐉 Challenges

  • Understanding Python type introspection deeply
  • Ensuring compatibility across typing and typing_extensions
  • Designing predictable and helpful error messages

🧑‍🚀 Authored by: Doby Baxter
🌌 Contribution for: ESA Pyxel Project

⚙️ Config Lab