Coverage for pyodmongo/services/verify_subclasses.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-16 15:08 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-16 15:08 +0000
1from typing import Any
2from types import NoneType
5def _rec_verify(class_list: list) -> list:
6 """
7 Recursively verify the class hierarchy and extend the class list with base classes.
9 Args:
10 class_list (list): A list of classes to be verified.
12 Returns:
13 list: The extended list of classes including all base classes.
14 """
15 for cls in class_list:
16 class_list += list(cls.__bases__)
17 return class_list
20def is_subclass(class_to_verify: Any, subclass: Any) -> bool:
21 """
22 Check if the class_to_verify is a subclass of the given subclass.
24 Args:
25 class_to_verify (Any): The class to be verified.
26 subclass (Any): The subclass to check against.
28 Returns:
29 bool: True if class_to_verify is a subclass of subclass, otherwise False.
30 """
31 if class_to_verify is NoneType:
32 return True
33 if (
34 class_to_verify is NoneType
35 or class_to_verify is None
36 or class_to_verify is subclass
37 ):
38 return True
39 subclasses = _rec_verify(class_list=list(class_to_verify.__bases__))
40 return subclass in subclasses