API reference#
earthcarekit.typing
Globally used types and validation functions.
Notes#
This module does not depend on other internal modules.
is_iterable_of_str
#
Checks if an object is a non-str iterable of strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
Object to validate. |
required |
max_checks
|
int | None
|
Maximum number of elements to inspect. If None, all elements are checked. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
TypeGuard[Iterable[str]]
|
TypeGuard[Iterable[str]]: True if |
Examples:
>>> is_iterable_of_str(["a", "b"])
True
>>> is_iterable_of_str("ab")
False
>>> is_iterable_of_str(["a", 2])
False
>>> is_iterable_of_str(["a", 2], max_checks=1)
True
Source code in earthcarekit/typing/_validation.py
is_iterable_of_type
#
Checks if an object is a non-str iterable of a given type T.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
Object to validate. |
required |
t
|
type
|
Expected type |
required |
max_checks
|
int | None
|
Maximum number of elements to inspect. If None, all elements are checked. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
TypeGuard[Iterable[T]]
|
TypeGuard[Iterable[T]]: True if |
Examples:
>>> is_iterable_of_type(["a", "b"], str)
True
>>> is_iterable_of_type("ab", str)
False
>>> is_iterable_of_type([1, 2], int)
True
>>> is_iterable_of_type([1, "b"], int)
False
>>> is_iterable_of_type([1, "b"], int, max_checks=1)
True
Source code in earthcarekit/typing/_validation.py
is_non_str_iter_seq
#
Checks if an object is a non-str iterable sequence.
is_non_str_iterable
#
is_non_str_sequence
#
Checks if an object is a non-str sequence.
is_non_str_sequence_of_length
#
is_non_str_sequence_of_length(
x: Any, length: int | None = None, min_length: int | None = None, max_length: int | None = None
) -> TypeGuard[Sequence]
Checks if an object is a non-str iterable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
Object to validate. |
required |
Returns:
| Type | Description |
|---|---|
TypeGuard[Sequence]
|
TypeGuard[Iterable]: True if |
Examples:
>>> is_non_str_sequence_of_length(["a", "b"])
True
>>> is_non_str_sequence_of_length(["a", "b"], length=2)
True
>>> is_non_str_sequence_of_length(["a", "b"], min_length=3)
False
>>> is_non_str_sequence_of_length("ab", str)
False
>>> is_non_str_sequence_of_length([1, 2])
True
>>> is_non_str_sequence_of_length([1, "b"])
True
Source code in earthcarekit/typing/_validation.py
validate_completeness_of_args
#
validate_completeness_of_args(
function_name: str,
required_names: Sequence[str],
positional_values: Sequence[Any] | None = None,
**kwargs
) -> list[str]
Validates that required positional and optional argument groups are complete.
For example, if required_names = ['x', 'y'], this function will:
- Check if x and y are both provided in positional arguments (if used).
- Check if optional arguments like x1, x2, ..., y1, y2, ... are all matched
across the required names (e.g., if x2 is given, y2 must also be present).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function_name
|
str
|
Name of the function (used in error messages). |
required |
required_names
|
Sequence[str]
|
Base names of required argument groups (e.g. ['x', 'y']). |
required |
positional_values
|
Sequence[Any]
|
Positional argument values to validate. |
None
|
**kwargs
|
Optional keyword arguments to validate for matching suffixes. |
{}
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List[str]: List of suffixes (as strings) used in optional arguments for the first group. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any required arguments are missing. |
Source code in earthcarekit/typing/_validation.py
validate_height_range
#
Returns validated height range and raises ValueError if invalid.
Source code in earthcarekit/typing/_validation.py
validate_numeric_pair
#
validate_numeric_pair(
input: NumberPairLike | NumberPairNoneLike, fallback: tuple[Number, Number] | None = None
) -> tuple[float, float]
Validates that the input is a pair with exactly 2 numeric elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
NumericPairLike | NumericPairNoneLike
|
A sequence of 2 numbers. |
required |
fallback
|
tuple[Number, Number]
|
Used to replace None values in |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
A tuple of two floats. |
Source code in earthcarekit/typing/_validation.py
validate_numeric_range
#
validate_numeric_range(
input: ValueRangeLike, fallback: tuple[Number, Number] | None = None
) -> tuple[float, float]
Validates that the input is a pair with exactly 2 numeric elements that monotonically increasing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
ValueRangeLike
|
A sequence of 2 numbers. |
required |
fallback
|
tuple[Number, Number]
|
Used to replace None values in |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
A tuple of monotonically increasing two floats. |