def test_isattributedescriptor(app): from target.methods import Base class Descriptor: def __get__(self, obj, typ=None): pass testinstancemethod = _testcapi.instancemethod(str.__repr__) assert inspect.isattributedescriptor(Base.prop) is True # property assert inspect.isattributedescriptor(Base.meth) is False # method assert inspect.isattributedescriptor( Base.staticmeth) is False # staticmethod assert inspect.isattributedescriptor(Base.classmeth) is False # classmetho assert inspect.isattributedescriptor( Descriptor) is False # custom descriptor class # NOQA assert inspect.isattributedescriptor( str.join) is False # MethodDescriptorType # NOQA assert inspect.isattributedescriptor( object.__init__) is False # WrapperDescriptorType # NOQA assert inspect.isattributedescriptor( dict.__dict__['fromkeys'] ) is False # ClassMethodDescriptorType # NOQA assert inspect.isattributedescriptor( types.FrameType.f_locals) is True # GetSetDescriptorType # NOQA assert inspect.isattributedescriptor( datetime.timedelta.days) is True # MemberDescriptorType # NOQA assert inspect.isattributedescriptor( testinstancemethod) is False # instancemethod (C-API) # NOQA
def test_isattributedescriptor(app): from target.methods import Base class Descriptor: def __get__(self, obj, typ=None): pass assert inspect.isattributedescriptor(Base.prop) is True # property assert inspect.isattributedescriptor(Base.meth) is False # method assert inspect.isattributedescriptor(Base.staticmeth) is False # staticmethod assert inspect.isattributedescriptor(Base.classmeth) is False # classmetho assert inspect.isattributedescriptor(Descriptor) is False # custom descriptor class # NOQA assert inspect.isattributedescriptor(str.join) is False # MethodDescriptorType # NOQA assert inspect.isattributedescriptor(object.__init__) is False # WrapperDescriptorType # NOQA assert inspect.isattributedescriptor(dict.__dict__['fromkeys']) is False # ClassMethodDescriptorType # NOQA assert inspect.isattributedescriptor(types.FrameType.f_locals) is True # GetSetDescriptorType # NOQA assert inspect.isattributedescriptor(datetime.timedelta.days) is True # MemberDescriptorType # NOQA try: # _testcapi module cannot be importable in some distro # refs: https://github.com/sphinx-doc/sphinx/issues/9868 import _testcapi testinstancemethod = _testcapi.instancemethod(str.__repr__) assert inspect.isattributedescriptor(testinstancemethod) is False # instancemethod (C-API) # NOQA except ImportError: pass
class InstanceMethod: id = _testcapi.instancemethod(id) testfunction = _testcapi.instancemethod(testfunction)