symforce.typing_util module

General python typing-related utilities

get_type(a)[source]

Returns the type of the element if its an instance, or a pass through if already a type.

Parameters:

a (Any) –

Return type:

Type

scalar_like(a)[source]

Returns whether the element is scalar-like (an int, float, or sympy expression).

This method does not rely on the value of a, only the type.

Parameters:

a (Any) –

Return type:

bool

get_sequence_from_dataclass_sequence_field(field, field_type)[source]
Parameters:
Return type:

Sequence[Any]

maybe_tuples_of_types_from_annotation(annotation, return_annotation_if_not_tuple=False)[source]

Attempt to construct a tuple of types from an annotation of the form T.Tuple[A, B, C] of any fixed length, recursively.

If this is not possible, because the annotation is not a T.Tuple, returns:

  1. The annotation itself, if return_annotation_if_not_tuple is True

  2. None, otherwise

If the annotation is a T.Tuple, but is of unknown length, returns None

Parameters:
  • annotation (Type | Any) –

  • return_annotation_if_not_tuple (bool) –

Return type:

Tuple[Tuple | Type] | Any | None