def test_get_mro_union(self): mro_u = get_mro(Union[int, str]) # Below is to stay compatible with Python 3.5+ super_cls = getattr(typing, '_GenericAlias', getattr(typing, 'GenericMeta', None)) expected = (typing.Union, super_cls, object) self.assertTupleEqual(expected, mro_u)
def test_get_mro_object(self): mro_b = get_mro(B()) self.assertTupleEqual((B, A, object), mro_b)
def _get_complete_class_dict(cls: type) -> dict: cls_dict = {} # Loop reversed so values of sub-classes override those of super-classes. for cls_or_elder in reversed(get_mro(cls)): cls_dict.update(cls_or_elder.__dict__) return cls_dict
def __subclasscheck__(cls, subclass: type) -> bool: if Unicode in get_mro(subclass): return cls.chars is Any or subclass.chars <= cls.chars return False
def __subclasscheck__(cls, subclass: type) -> bool: return Bool in get_mro(subclass)
def __subclasscheck__(cls, subclass: type) -> bool: return Datetime64 in get_mro(subclass)
def __subclasscheck__(cls, subclass: type) -> bool: return Timedelta64 in get_mro(subclass)
def _is_a(this: Any, that: type) -> bool: # Return whether this is a subclass of that, considering the mro. return that in get_mro(this)