Beispiel #1
0
    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)
Beispiel #2
0
 def test_get_mro_object(self):
     mro_b = get_mro(B())
     self.assertTupleEqual((B, A, object), mro_b)
Beispiel #3
0
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
Beispiel #4
0
 def __subclasscheck__(cls, subclass: type) -> bool:
     if Unicode in get_mro(subclass):
         return cls.chars is Any or subclass.chars <= cls.chars
     return False
Beispiel #5
0
 def __subclasscheck__(cls, subclass: type) -> bool:
     return Bool in get_mro(subclass)
Beispiel #6
0
 def __subclasscheck__(cls, subclass: type) -> bool:
     return Datetime64 in get_mro(subclass)
Beispiel #7
0
 def __subclasscheck__(cls, subclass: type) -> bool:
     return Timedelta64 in get_mro(subclass)
Beispiel #8
0
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)