Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PathPair & PathPairCollection validation; add path_pair type hint fn; use path_pair in Topmodel init_config model #183

Merged
merged 8 commits into from
Sep 6, 2024

Conversation

aaraney
Copy link
Member

@aaraney aaraney commented Aug 30, 2024

ngen.config

Additions

Changes

  • Fix PathPair & PathPairCollection model validation
  • Use path_pair type hint function in Topmodel init_config model
  • AbstractPathPairMixin.read return type hint correct to bool. Already returned bool, type hint was missing.

Feature Details

path_pair type hint function:

In nearly all cases, this should be used as the pydantic model field type if the field is to be a PathPair[T]. This will ensure that the PathPair[T] instance has the specified serializer, deserializer, reader, and writer.

NOTE: if a PathPair instance is passed to a model field defined using this function during initialization of the model, any serializer, deserializer, reader, or writer on the PathPair instance will not be replaced by the inputs provided to this function.

NOTE: if a pydantic model's field type is defined using this function, it's ModelField.type_ will be a PathPairOptions.

Example:

import typing
import pydantic
from ngen.config.path_pair import (
    PathPair,
    pydantic_serializer,
    pydantic_deserializer,
)

class Model(pydantic.BaseModel):
    field: int

class Foo(pydantic.BaseModel):
    # make static type checkers happy
    if typing.TYPE_CHECKING:
        path: PathPair[Model]
    else:
        path: path_pair(
            Model,
            serializer=pydantic_serializer,
            deserializer=pydantic_deserializer(Model),
        )

@aaraney aaraney self-assigned this Aug 30, 2024
@aaraney aaraney added feat New software feature; Not build script / CI feature fix Bug fix ngen.config Related to ngen.config package labels Aug 30, 2024
@classmethod
def __get_validators__(cls) -> CallableGenerator:
yield from PathPair[cls.ty].__get_validators__()
# apply all validators, now `value` is guaranteed to be a `PathPair`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which value?

@hellkite500 hellkite500 merged commit 40f0bd3 into NOAA-OWP:master Sep 6, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New software feature; Not build script / CI feature fix Bug fix ngen.config Related to ngen.config package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants