diff options
Diffstat (limited to 'gn3/auth')
-rw-r--r-- | gn3/auth/dictify.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/gn3/auth/dictify.py b/gn3/auth/dictify.py new file mode 100644 index 0000000..274ebb0 --- /dev/null +++ b/gn3/auth/dictify.py @@ -0,0 +1,17 @@ +"""Module for dictifying objects""" + +from typing import Any + +# TYPE = TypeVar("TYPE") + +__dictifiers__ = {}#: dict[TYPE, Callable[[TYPE], dict[str, Any]]] = {} + +# def register_dictifier(obj_type: TYPE, dictifier: Callable[[TYPE], dict[str, Any]]): +def register_dictifier(obj_type, dictifier): + """Register a new dictifier function""" + global __dictifiers__ # pylint: disable=[global-variable-not-assigned] + __dictifiers__[obj_type] = dictifier + +def dictify(obj: Any) -> dict[str, Any]: + """Turn `obj` to a dict representation.""" + return __dictifiers__[type(obj)](obj) |