Пример #1
0
def test_isclassmethod(app):
    from target.methods import Base, Inherited

    assert inspect.isclassmethod(Base.classmeth) is True
    assert inspect.isclassmethod(Base.meth) is False
    assert inspect.isclassmethod(Inherited.classmeth) is True
    assert inspect.isclassmethod(Inherited.meth) is False
Пример #2
0
    def import_object(self):
        # type: () -> Any
        ret = ClassLevelDocumenter.import_object(self)
        if not ret:
            return ret

        # get parent's class
        parent_cls = self.parent
        if not isinstance(parent_cls, type):
            parent_cls = parent_cls.__class__  # if instance, get its class

        # to distinguish classmethod/staticmethod
        obj = parent_cls.__dict__.get(self.object_name)
        if obj is None:
            obj = self.object

        if isclassmethod(obj):
            self.directivetype = 'classmethod'
            # document class and static members before ordinary ones
            self.member_order = self.member_order - 1
        elif isstaticmethod(obj, cls=parent_cls, name=self.object_name):
            self.directivetype = 'staticmethod'
            # document class and static members before ordinary ones
            self.member_order = self.member_order - 1
        else:
            self.directivetype = 'method'
        return ret
Пример #3
0
def test_isclassmethod():
    class Foo():
        @classmethod
        def method1(cls):
            pass

        def method2(self):
            pass

        @property
        def value(self):
            return "Test"

    class Bar(Foo):
        pass

    assert inspect.isclassmethod(Foo.method1) is True
    assert inspect.isclassmethod(Foo.method2) is False
    assert inspect.isclassmethod(Foo.value) is False
    assert inspect.isclassmethod(Bar.method1) is True
    assert inspect.isclassmethod(Bar.method2) is False
    assert inspect.isclassmethod(Bar.value) is False