def test_isstaticmethod(app):
    from target.methods import Base, Inherited

    assert inspect.isstaticmethod(Base.staticmeth, Base, 'staticmeth') is True
    assert inspect.isstaticmethod(Base.meth, Base, 'meth') is False
    assert inspect.isstaticmethod(Inherited.staticmeth, Inherited, 'staticmeth') is True
    assert inspect.isstaticmethod(Inherited.meth, Inherited, 'meth') is False
Exemple #2
0
def test_isstaticmethod():
    class Foo():
        @staticmethod
        def method1():
            pass

        def method2(self):
            pass

    class Bar(Foo):
        pass

    assert inspect.isstaticmethod(Foo.method1, Foo, 'method1') is True
    assert inspect.isstaticmethod(Foo.method2, Foo, 'method2') is False
    assert inspect.isstaticmethod(Bar.method1, Bar, 'method1') is True
    assert inspect.isstaticmethod(Bar.method2, Bar, 'method2') is False
Exemple #3
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
Exemple #4
0
	def process_overload_signature(self, overload: Signature) -> Signature:
		"""
		Processes the signature of the given overloaded implementation.

		:param overload:
		"""

		__globals__ = safe_getattr(self.object, "__globals__", {})
		overload = evaluate_signature(overload, __globals__)

		if not inspect.isstaticmethod(self.object, cls=self.parent, name=self.object_name):
			overload = overload.replace(parameters=list(overload.parameters.values())[1:])

		return super().process_overload_signature(overload)
Exemple #5
0
def test_isstaticmethod():
    class Foo():
        @staticmethod
        def method1():
            pass

        def method2(self):
            pass

    class Bar(Foo):
        pass

    assert inspect.isstaticmethod(Foo.method1, Foo, 'method1') is True
    assert inspect.isstaticmethod(Foo.method2, Foo, 'method2') is False

    if sys.version_info < (3, 0):
        assert inspect.isstaticmethod(Bar.method1, Bar, 'method1') is False
        assert inspect.isstaticmethod(Bar.method2, Bar, 'method2') is False
    else:
        assert inspect.isstaticmethod(Bar.method1, Bar, 'method1') is True
        assert inspect.isstaticmethod(Bar.method2, Bar, 'method2') is False
Exemple #6
0
def test_isstaticmethod():
    class Foo():
        @staticmethod
        def method1():
            pass

        def method2(self):
            pass

    class Bar(Foo):
        pass

    assert inspect.isstaticmethod(Foo.method1, Foo, 'method1') is True
    assert inspect.isstaticmethod(Foo.method2, Foo, 'method2') is False

    if sys.version_info < (3, 0):
        assert inspect.isstaticmethod(Bar.method1, Bar, 'method1') is False
        assert inspect.isstaticmethod(Bar.method2, Bar, 'method2') is False
    else:
        assert inspect.isstaticmethod(Bar.method1, Bar, 'method1') is True
        assert inspect.isstaticmethod(Bar.method2, Bar, 'method2') is False
def test_isstaticmethod():
    class Foo():
        @staticmethod
        def method1():
            pass

        def method2(self):
            pass

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

    class Bar(Foo):
        pass

    assert inspect.isstaticmethod(Foo.method1, Foo, 'method1') is True
    assert inspect.isstaticmethod(Foo.method2, Foo, 'method2') is False
    assert inspect.isstaticmethod(Foo.value, Foo, 'value') is False
    assert inspect.isstaticmethod(Bar.method1, Bar, 'method1') is True
    assert inspect.isstaticmethod(Bar.method2, Bar, 'method2') is False
    assert inspect.isstaticmethod(Bar.value, Bar, 'value') is False