Add pydantic validation decorators to epoch and ontology modules#19
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
TYPE_CHECKINGguard forClockTypeimport to make it available at runtime@pydantic.validate_calldecorator toepochclock(),t0_t1(),epochid(),epochnumber(), andepochtableentry()methodsFieldconstraintge=1(greater than or equal to 1) toepoch_numberparameters to validate that epoch numbers are >= 1epoch_number < 1checks (now handled by Pydantic)providers.py:
@pydantic.validate_calldecorator tolookup_term()methods across all provider classes:OntologyProvider,OLSProvider,OMProvider,NDICProvider,NCImProvider,NCBITaxonProvider,WBStrainProvider,RRIDProvider,PubChemProvider, andEMPTYProviderontology/init.py:
@pydantic.validate_calldecorator to thelookup()functionlru_cache,Path,Dict,List,Optional,Tuple)functions.py:
@pydantic.validate_calldecorator withConfigDict(arbitrary_types_allowed=True)toepochrange()andfindepochnode()functions to allow validation of custom types likeClockTypeepoch.py:
@pydantic.validate_calldecorator withConfigDict(arbitrary_types_allowed=True)tois_epoch_or_empty()functionepochprobemap.py:
@pydantic.validate_calldecorator toparse_devicestring()andbuild_devicestring()functionsepochprobemap_daqsystem.py:
@pydantic.validate_calldecorator tosavetofile()methodepoch/init.py:
build_devicestringandparse_devicestringfunctions in the module's public APIImplementation Details
Annotated[int, Field(ge=1)]pattern for epoch number validation to enforce minimum value constraints at the type levelConfigDict(arbitrary_types_allowed=True)where functions accept custom types (e.g.,ClockType) that Pydantic doesn't natively understandhttps://claude.ai/code/session_01RoNGaAUDsDLzPLhMLVutbZ