parselglossy.types module#

parselglossy.types.type_fixers: Dict[str, Callable[[Any], Any]] = {'List[bool]': <function <lambda>>, 'List[complex]': <function <lambda>>, 'List[float]': <function <lambda>>, 'List[int]': <function <lambda>>, 'List[str]': <function <lambda>>, 'bool': <class 'bool'>, 'complex': <class 'complex'>, 'float': <class 'float'>, 'int': <class 'int'>, 'str': <class 'str'>}#

dictionary holding functions for type fixation.

Type

Dict[str, Callable[[Any], Any]]

parselglossy.types.type_matches(value: Union[bool, str, int, float, complex, List[bool], List[str], List[int], List[float], List[complex]], expected_type: str) Optional[bool][source]#

Checks whether a value is of the expected type.

Parameters
  • value (AllowedTypes) – Value whose type needs to be checked

  • expected_type (str) –

Notes

Allowed types T are: str, int, float, complex, bool, as well as List[T].

Return type

True if value has the type expected_type, otherwise False.

Raises

ValueError – If expected_type is not among the allowed types.

Notes

Complex numbers are a tad more fastidious, as they might be read in as strings. To avoid false negatives, we have a nasty hack, for which RDR will forever burn in hell. For complex and List[complex] we will re-run type checking after type casting if and only if:

  • We expected complex and List[complex].

  • We got a str or List[str].

  • The string are in the right format for the type casting operator.