Beispiel #1
0
def test_get_class_that_define_method():
    class A:
        def foo(self):
            pass  # pragma no cover

        @classmethod
        def bar(cls):
            pass  # pragma no cover

        def foobar(self):
            pass  # pragma no cover

    class B(A):
        def foobar(self):
            pass  # pragma no cover

    assert get_class_that_define_method("foo", B) == A
    assert get_class_that_define_method("bar", B) == A
    assert get_class_that_define_method("foobar", B) == B
Beispiel #2
0
 def get_declared_hook(self, method_name: str):
     if not hasattr(self.cls, method_name):
         return
     cls = get_class_that_define_method(method_name, self.cls)
     if type_name(cls) != DataClassDictMixinPath:
         return cls.__dict__[method_name]
Beispiel #3
0
 def get_declared_hook(self, method_name: str):
     if not hasattr(self.cls, method_name):
         return
     cls = get_class_that_define_method(method_name, self.cls)
     if not is_dataclass_dict_mixin(cls):
         return cls.__dict__[method_name]