Utils#
Utility functions used internally across the library
Exceptions:
Exception type for when |
Classes:
Mixin to allow objects to become aware of all the arguments they were called with on initialization |
Functions:
|
Given some class, find its subclasses recursively |
|
Given some path in a python package, import all modules beneath it |
|
Gather a list of dictionaries like. |
|
Deduplicate a list of dicts. |
- exception onice_conversion.utils.AmbiguityError#
Bases:
Exception
Exception type for when
onice_conversion.spec
modules give ambiguous results
- class onice_conversion.utils.IntrospectionMixin#
Bases:
object
Mixin to allow objects to become aware of all the arguments they were called with on initialization
Call
_get_init_args()
in the __init__ method of any object that inherits from this mixin :)Methods:
introspect object and get all arguments passed on __init__
Returns the full module and class name of an object, eg.
- _get_init_args()#
introspect object and get all arguments passed on __init__
depends on introspecting up frames so should only be called during the top-level __init__ of the base class :)
- Return type
dict of argument names and params
- onice_conversion.utils._recurse_subclasses(cls, leaves_only=True) list #
Given some class, find its subclasses recursively
See: https://stackoverflow.com/a/17246726/13113166
- Parameters
leave_only (bool) – If True, only include classes that have no further subclasses,
if False, return all subclasses.
- Returns
list of subclasses
- onice_conversion.utils._recursive_import(module_name: str) List[str] #
Given some path in a python package, import all modules beneath it
- Parameters
module_name (str) – name of module to recursively import
- Returns
list of all modules that were imported
- onice_conversion.utils._gather_list_of_dicts(a_list: list) Dict[str, list] #
Gather a list of dictionaries like:
[{'key1':'val1'}, {'key1':'val2'}, {'key1':'val3'}]
to a dict of lists like:
{‘key1’: [‘val1’, ‘val2’, ‘val3’]}
- onice_conversion.utils._recursive_dedupe_dicts(a_dict, raise_on_dupes=True)#
Deduplicate a list of dicts.
Optionally raise an exception if duplicates are found, otherwise call
set
and unwrap singletons and return- Parameters
a_dict (of dicts)
- Returns
dict
- Return type
deduplicated dictionary