From 50d07d1997876a7c64e82c3c86e97f238bda29f5 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 23 Jan 2023 14:40:20 +0300 Subject: auth: Add missing module --- gn3/auth/dictify.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 gn3/auth/dictify.py (limited to 'gn3') 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) -- cgit v1.2.3