nemo_microservices._utils._transform#

Module Contents#

Classes#

PropertyInfo

Metadata class to be used in Annotated types to provide information about a given type.

Functions#

async_maybe_transform

Wrapper over async_transform() that allows None to be passed.

async_transform

Transform dictionaries based off of type information from the given type, for example:

get_type_hints

maybe_transform

Wrapper over transform() that allows None to be passed.

transform

Transform dictionaries based off of type information from the given type, for example:

Data#

API#

nemo_microservices._utils._transform.PropertyFormat#

None

class nemo_microservices._utils._transform.PropertyInfo(
*,
alias: str | None = None,
format: nemo_microservices._utils._transform.PropertyFormat | None = None,
format_template: str | None = None,
discriminator: str | None = None,
)#

Metadata class to be used in Annotated types to provide information about a given type.

For example:

class MyParams(TypedDict): account_holder_name: Annotated[str, PropertyInfo(alias=’accountHolderName’)]

This means that {‘account_holder_name’: ‘Robert’} will be transformed to {‘accountHolderName’: ‘Robert’} before being sent to the API.

Initialization

alias: str | None#

None

discriminator: str | None#

None

format: nemo_microservices._utils._transform.PropertyFormat | None#

None

format_template: str | None#

None

async nemo_microservices._utils._transform.async_maybe_transform(
data: object,
expected_type: object,
) Any | None#

Wrapper over async_transform() that allows None to be passed.

See async_transform() for more details.

async nemo_microservices._utils._transform.async_transform(
data: nemo_microservices._utils._transform._T,
expected_type: object,
) nemo_microservices._utils._transform._T#

Transform dictionaries based off of type information from the given type, for example:

class Params(TypedDict, total=False):
    card_id: Required[Annotated[str, PropertyInfo(alias="cardID")]]


transformed = transform({"card_id": "<my card ID>"}, Params)
# {'cardID': '<my card ID>'}

Any keys / data that does not have type information given will be included as is.

It should be noted that the transformations that this function does are not represented in the type system.

nemo_microservices._utils._transform.get_type_hints(
obj: Any,
globalns: dict[str, Any] | None = None,
localns: Mapping[str, Any] | None = None,
include_extras: bool = False,
) dict[str, Any]#
nemo_microservices._utils._transform.maybe_transform(data: object, expected_type: object) Any | None#

Wrapper over transform() that allows None to be passed.

See transform() for more details.

nemo_microservices._utils._transform.transform(
data: nemo_microservices._utils._transform._T,
expected_type: object,
) nemo_microservices._utils._transform._T#

Transform dictionaries based off of type information from the given type, for example:

class Params(TypedDict, total=False):
    card_id: Required[Annotated[str, PropertyInfo(alias="cardID")]]


transformed = transform({"card_id": "<my card ID>"}, Params)
# {'cardID': '<my card ID>'}

Any keys / data that does not have type information given will be included as is.

It should be noted that the transformations that this function does are not represented in the type system.