diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index a05110496..ddc7ee5ef 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -224,6 +224,12 @@ def iscoroutinefunction(obj): return False +def isproperty(obj): + # type: (Any) -> bool + """Check if the object is property.""" + return isinstance(obj, property) + + def safe_getattr(obj, name, *defargs): # type: (Any, str, str) -> object """A getattr() that turns all exceptions into AttributeErrors.""" diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py index c298e2c64..c80b2b7c8 100644 --- a/tests/test_util_inspect.py +++ b/tests/test_util_inspect.py @@ -475,3 +475,14 @@ def test_isattributedescriptor(app): 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_isproperty(app): + from target.functions import func + from target.methods import Base + + assert inspect.isproperty(Base.prop) is True # property of class + assert inspect.isproperty(Base().prop) is False # property of instance + assert inspect.isproperty(Base.meth) is False # method of class + assert inspect.isproperty(Base().meth) is False # method of instance + assert inspect.isproperty(func) is False # function