hyped.core.features.engine module

DType Handling and Validation Module.

This module provides utilities for type validation, type variable registration, and type checking within a data flow graph system. It allows dynamic handling of type annotations, argument validation, and captures type variables during function calls. It integrates with Pydantic to handle model validation.

class hyped.core.features.engine.FeatureEngine(name: str, config: BaseConfig, signature: Signature)[source]

Bases: object

Feature Engine.

The FeatureEngine ensures that the input features conform to the expected types defined in the function’s signature and uses the type annotations to construct output features dynamically.

build_feature_with_context(annotation: Any, inputs: None | dict[str, Feature]) Feature[source]

Create a feature based on type annotation and inputs in a specific context.

Parameters:
  • annotation (Any) – DType annotation for the feature.

  • inputs (None | dict[str, Feature]) – Input features to build the feature, if any.

Returns:

The constructed feature.

Return type:

Feature

build_return_feature(inputs: dict[str, Feature]) Feature[source]

Build the return feature based on the function’s return type annotation.

Parameters:
  • ref (Reference) – Reference to the return feature.

  • inputs (dict[str, Feature]) – Input features for constructing the return feature.

Returns:

The constructed return feature.

Return type:

Feature

get_features_and_objects(*args: Feature | Any, **kwargs: Feature | Any) tuple[dict[str, Feature], dict[str, Any], dict[str, DType]][source]

Separate input feature references and constants from the arguments.

Parameters:
  • *args (Feature | Any) – Positional arguments.

  • **kwargs (Feature | Any) – Keyword arguments.

Returns:

Tuple containing input features and objects.

Return type:

tuple[dict[str, Feature], dict[str, Any], dict[str, DType]]

validate_arguments(*args: Any, **kwargs: Any) None[source]

Validate the arguments passed to the function based on its signature.

Parameters:
  • *args (Any) – Positional arguments.

  • **kwargs (Any) – Keyword arguments.

Raises:

TypeError – If the arguments provided are invalid or do not match the expected types.

validate_signature() None[source]

Validate that the function signature has all necessary type annotations.

Raises:

TypeError – If any parameter is missing a type annotation.

class hyped.core.features.engine.TypeVarRegister[source]

Bases: object

A registry for managing and capturing TypeVars used in type validation.

create_trackable_typevar(*args: Any, **kwargs: Any) TypeVar[source]

Create and register a TypeVar with a custom validator.

Parameters:
  • *args (Any) – Positional arguments passed to the TypeVar constructor.

  • **kwargs (Any) – Keyword arguments passed to the TypeVar constructor. Special bound keyword is used to define the type bound for the TypeVar.

Returns:

The newly created and registered TypeVar with the custom validator.

Return type:

TypeVar

create_validator()[source]

Create a Pydantic validator to validate and capture TypeVars.

Returns:

A Pydantic validator function with an associated UUID.

Return type:

Callable

register(t: TypeVar, validator: AfterValidator) None[source]

Register a TypeVar with a Pydantic validator.

Parameters:
  • t (TypeVar) – The TypeVar to register.

  • validator (pydantic.AfterValidator) – The validator associated with the TypeVar.

reset() None[source]

Reset the type var register.

solve_typevar(var: TypeVar) DType[source]

Resolve a TypeVar to its captured type.

Parameters:

var (TypeVar) – The TypeVar to resolve.

Returns:

The captured type associated with the provided TypeVar.

Return type:

type

Raises:

KeyError – If the TypeVar is not found in the captured variables.

property typevar_mapping: dict[TypeVar, DType]

Map captured TypeVars to their resolved types.

Returns:

A dictionary mapping each registered TypeVar to its resolved type.

Return type:

dict[TypeVar, type]