ytilities.classes

Copyright (c) 2023 Anthony Mugendi

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

Module Contents

Functions

is_class(→ bool)

Return True if the value is a class .

is_initialized(→ bool)

Returns True if the given class is initialize .

get_props(→ Union[list, dict])

List all (non default) properties of a class .

get_prop_values(→ dict)

Get property values of a class/object .

ytilities.classes.is_class(cls) bool

Return True if the value is a class .

Returns:

True if class

Return type:

bool

ytilities.classes.is_initialized(cls) bool

Returns True if the given class is initialize .

Raises:

TypeError – if cls argument is not a class

Returns:

True if class has been initialized

Return type:

bool

ytilities.classes.get_props(cls, filter_callable: bool = False, with_meta: bool = False) list | dict

List all (non default) properties of a class .

Parameters:
  • cls (Any) – a valid class

  • filter_callable (bool, optional) – if True, only callable properties of the class are returned. Defaults to False.

  • with_meta (bool, optional) – if True, a dict of properties and metadata about them is returned. Defaults to False.

Returns:

list or dict of properties of the class

Return type:

list|dict

ytilities.classes.get_prop_values(obj: Any, decode_bytes: bool = True, run_callable: bool = False, skip_callable: bool = True) dict

Get property values of a class/object .

Parameters:
  • obj (Any) – the object to get properties from

  • decode_bytes (bool, optional) – try and decode any byte values to utf-8. Defaults to True.

  • run_callable (bool, optional) – try and run callable properties. Defaults to False.

  • skip_callable (bool, optional) – determines if to include callable values in response. Defaults to True.

Returns:

a dict of {property:value} pairs

Return type:

dict