ytilities.types

Copyright (c) 2023 Anthony Mugendi

This software is released under the MIT License. https://opensource.org/licenses/MIT

Module Contents

Functions

get_type_name(→ str)

Return the type name of a Python object. This returns full names for types so that str=>"string" and so on...

ensure_type(→ None)

Ensure that value is of a valid type .

Attributes

types_obj

ytilities.types.types_obj
ytilities.types.get_type_name(_type) str

Return the type name of a Python object. This returns full names for types so that str=>”string” and so on…

Parameters:

_type (type) – the type you want to get the name of. Example get_type_name(str) -> “string”

Returns:

full name of the type

Return type:

str

ytilities.types.ensure_type(val: Any, _types, val_name: str = None) None

Ensure that value is of a valid type .

Parameters:
  • val (Any) – value you want to ensure type for

  • _types (type, tuple(type)) – the data types you want to validate against. E.g (str,int,float)

  • val_name (str, optional) – the actual name of the variable you are validating. Example `ensure_type(var_1, (int, float), ‘var_1’). Defaults to None.

Raises:

TypeError – if value does not match the validation types entered