type_utils#

Helpers for type introspection and type-checking.

Functions#

assert_never()

Assertion for statically checking exhaustive pattern matches.

get_element_type()

Return the Python type of the non-None elements of a list.

get_immutable_types()

Returns the types that are considered immutable by the privacy framework.

assert_never(x)#

Assertion for statically checking exhaustive pattern matches.

From https://github.com/python/mypy/issues/5818.

Parameters

x (NoReturn) –

Return type

NoReturn

get_element_type(l, allow_none=True)#

Return the Python type of the non-None elements of a list.

If the given list is empty or contains elements with multiple types, raises ValueError.

If allow_none is true (the default), None values in the list are ignored; if the list contains only None values, NoneType is returned. If allow_none is false, raises ValueError if any element of the list is None.

Parameters
  • l (Sequence[Any]) –

  • allow_none (bool) –

Return type

type

get_immutable_types()#

Returns the types that are considered immutable by the privacy framework.

While many of these types are technically mutable in python, we assume that users do not mutate their state after creating them or passing them to another object.

Return type

Tuple[Type, …]