nemo_microservices._utils._utils#
Module Contents#
Functions#
Minimal reimplementation of copy.deepcopy() that will only copy certain object types: |
|
Recursively extract files from the given dictionary based on specified paths. |
|
Translates a mapping / sequence recursively in the same fashion
as |
|
A version of functools.lru_cache that retains the type signature for the wrapped function arguments. |
|
Add single quotation marks around the given string. Does not do any escaping. |
|
Remove a prefix from a string. |
|
Remove a suffix from a string. |
|
Decorator to enforce a given set of arguments or variants of arguments are passed to the decorated function. |
|
Remove all top-level keys where their values are instances of |
Data#
API#
- nemo_microservices._utils._utils.CallableT#
‘TypeVar(…)’
- nemo_microservices._utils._utils.coerce_boolean(val: str) bool#
- nemo_microservices._utils._utils.coerce_float(val: str) float#
- nemo_microservices._utils._utils.coerce_integer(val: str) int#
- nemo_microservices._utils._utils.deepcopy_minimal(
- item: nemo_microservices._utils._utils._T,
Minimal reimplementation of copy.deepcopy() that will only copy certain object types:
mappings, e.g.
dictlist
This is done for performance reasons.
- nemo_microservices._utils._utils.extract_files(
- query: Mapping[str, object],
- *,
- paths: Sequence[Sequence[str]],
Recursively extract files from the given dictionary based on specified paths.
A path may look like this [‘foo’, ‘files’, ‘
’, ‘data’]. Note: this mutates the given dictionary.
- nemo_microservices._utils._utils.file_from_path(path: str) nemo_microservices._types.FileTypes#
- nemo_microservices._utils._utils.flatten(
- t: Iterable[Iterable[nemo_microservices._utils._utils._T]],
- nemo_microservices._utils._utils.get_async_library() str#
- nemo_microservices._utils._utils.get_required_header(
- headers: nemo_microservices._types.HeadersLike,
- header: str,
- nemo_microservices._utils._utils.human_join(
- seq: Sequence[str],
- *,
- delim: str = ', ',
- final: str = 'or',
- nemo_microservices._utils._utils.is_dict(
- obj: object,
- nemo_microservices._utils._utils.is_given(
- obj: nemo_microservices._utils._utils._T | nemo_microservices._types.NotGiven | nemo_microservices._types.Omit,
- nemo_microservices._utils._utils.is_iterable(
- obj: object,
- nemo_microservices._utils._utils.is_list(obj: object) typing_extensions.TypeGuard[list[object]]#
- nemo_microservices._utils._utils.is_mapping(
- obj: object,
- nemo_microservices._utils._utils.is_mapping_t(
- obj: nemo_microservices._utils._utils._MappingT | object,
- nemo_microservices._utils._utils.is_sequence(
- obj: object,
- nemo_microservices._utils._utils.is_sequence_t(
- obj: nemo_microservices._utils._utils._SequenceT | object,
- nemo_microservices._utils._utils.is_tuple(
- obj: object,
- nemo_microservices._utils._utils.is_tuple_t(
- obj: nemo_microservices._utils._utils._TupleT | object,
- nemo_microservices._utils._utils.json_safe(data: object) object#
Translates a mapping / sequence recursively in the same fashion as
pydanticv2’smodel_dump(mode="json").
- nemo_microservices._utils._utils.lru_cache(
- *,
- maxsize: int | None = 128,
A version of functools.lru_cache that retains the type signature for the wrapped function arguments.
- nemo_microservices._utils._utils.maybe_coerce_boolean(val: str | None) bool | None#
- nemo_microservices._utils._utils.maybe_coerce_float(val: str | None) float | None#
- nemo_microservices._utils._utils.maybe_coerce_integer(val: str | None) int | None#
- nemo_microservices._utils._utils.quote(string: str) str#
Add single quotation marks around the given string. Does not do any escaping.
- nemo_microservices._utils._utils.removeprefix(string: str, prefix: str) str#
Remove a prefix from a string.
Backport of
str.removeprefixfor Python < 3.9
- nemo_microservices._utils._utils.removesuffix(string: str, suffix: str) str#
Remove a suffix from a string.
Backport of
str.removesuffixfor Python < 3.9
- nemo_microservices._utils._utils.required_args(
- *variants: Sequence[str],
Decorator to enforce a given set of arguments or variants of arguments are passed to the decorated function.
Useful for enforcing runtime validation of overloaded functions.
Example usage:
@overload def foo(*, a: str) -> str: ... @overload def foo(*, b: bool) -> str: ... # This enforces the same constraints that a static type checker would # i.e. that either a or b must be passed to the function @required_args(["a"], ["b"]) def foo(*, a: str | None = None, b: bool | None = None) -> str: ...
- nemo_microservices._utils._utils.strip_not_given(obj: object | None) object#
Remove all top-level keys where their values are instances of
NotGiven