Skip to content

Add pydantic validation decorators to epoch and ontology modules#19

Merged
stevevanhooser merged 1 commit into
mainfrom
claude/apply-python-porting-guide-lVXML
Mar 11, 2026
Merged

Add pydantic validation decorators to epoch and ontology modules#19
stevevanhooser merged 1 commit into
mainfrom
claude/apply-python-porting-guide-lVXML

Conversation

@stevevanhooser

Copy link
Copy Markdown
Contributor

Summary

This PR adds Pydantic validation decorators (@pydantic.validate_call) to multiple functions and methods across the epoch and ontology modules to enable runtime input validation using Pydantic's validation framework.

Key Changes

  • epochset.py:

    • Removed TYPE_CHECKING guard for ClockType import to make it available at runtime
    • Added @pydantic.validate_call decorator to epochclock(), t0_t1(), epochid(), epochnumber(), and epochtableentry() methods
    • Added Pydantic Field constraint ge=1 (greater than or equal to 1) to epoch_number parameters to validate that epoch numbers are >= 1
    • Simplified validation logic by removing redundant epoch_number < 1 checks (now handled by Pydantic)
  • providers.py:

    • Added @pydantic.validate_call decorator to lookup_term() methods across all provider classes: OntologyProvider, OLSProvider, OMProvider, NDICProvider, NCImProvider, NCBITaxonProvider, WBStrainProvider, RRIDProvider, PubChemProvider, and EMPTYProvider
  • ontology/init.py:

    • Added @pydantic.validate_call decorator to the lookup() function
    • Removed unused imports (lru_cache, Path, Dict, List, Optional, Tuple)
  • functions.py:

    • Added @pydantic.validate_call decorator with ConfigDict(arbitrary_types_allowed=True) to epochrange() and findepochnode() functions to allow validation of custom types like ClockType
  • epoch.py:

    • Added @pydantic.validate_call decorator with ConfigDict(arbitrary_types_allowed=True) to is_epoch_or_empty() function
  • epochprobemap.py:

    • Added @pydantic.validate_call decorator to parse_devicestring() and build_devicestring() functions
  • epochprobemap_daqsystem.py:

    • Added @pydantic.validate_call decorator to savetofile() method
  • epoch/init.py:

    • Exported build_devicestring and parse_devicestring functions in the module's public API

Implementation Details

  • Used Annotated[int, Field(ge=1)] pattern for epoch number validation to enforce minimum value constraints at the type level
  • Applied ConfigDict(arbitrary_types_allowed=True) where functions accept custom types (e.g., ClockType) that Pydantic doesn't natively understand
  • Maintained backward compatibility by keeping all existing function signatures and behavior

https://claude.ai/code/session_01RoNGaAUDsDLzPLhMLVutbZ

Add @pydantic.validate_call to all public functions and methods in
ndi.epoch and ndi.ontology modules per the porting guide's mandatory
Pydantic input validation rule (Section 4).

Changes:
- epoch.py: Add @validate_call to is_epoch_or_empty()
- epochprobemap.py: Add @validate_call to parse_devicestring(),
  build_devicestring(); export them from __init__.py
- epochprobemap_daqsystem.py: Add @validate_call to savetofile()
- epochset.py: Add @validate_call with Annotated[int, Field(ge=1)]
  constraints on epochclock(), t0_t1(), epochid(), epochnumber(),
  epochtableentry(); move ClockType to runtime import
- functions.py: Add @validate_call to epochrange(), findepochnode()
  with ConfigDict(arbitrary_types_allowed=True)
- ontology/__init__.py: Add @validate_call to lookup(); remove
  unused imports (lru_cache, Path, Dict, List, Optional, Tuple)
- ontology/providers.py: Add @validate_call to lookup_term() on
  OntologyProvider base class and all 11 provider subclasses

All 112 tests pass. Ruff and Black clean.

https://claude.ai/code/session_01RoNGaAUDsDLzPLhMLVutbZ
@stevevanhooser stevevanhooser merged commit ded2cb1 into main Mar 11, 2026
1 of 4 checks passed
@stevevanhooser stevevanhooser deleted the claude/apply-python-porting-guide-lVXML branch March 11, 2026 23:31
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.

2 participants