Utility method to derive a key for a custom class representing the fully qualified name of that class.
Parameters: |
-
custom_class
(Type )
–
The custom class object for which to derive a key.
|
Returns: |
-
str ( str
) –
The fully qualified name of the class in lowercase (e.g. module.submodule.class).
|
Source code in src/pyobjson/utils.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48 | def derive_custom_class_key(custom_class: Type) -> str:
"""Utility method to derive a key for a custom class representing the fully qualified name of that class.
Args:
custom_class (Type): The custom class object for which to derive a key.
Returns:
str: The fully qualified name of the class in lowercase (e.g. module.submodule.class).
"""
# avoid including module if no module exists or the class is in the Python builtins
if (cls_module := getattr(custom_class, "__module__", None)) and cls_module != "builtins":
return f"{cls_module.lower()}.{custom_class.__qualname__.lower()}"
else:
return custom_class.__qualname__.lower()
|