mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add sphinx.util.inspect:isproperty()
This commit is contained in:
parent
a142a654fc
commit
c59f2d9545
@ -224,6 +224,12 @@ def iscoroutinefunction(obj):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def isproperty(obj):
|
||||||
|
# type: (Any) -> bool
|
||||||
|
"""Check if the object is property."""
|
||||||
|
return isinstance(obj, property)
|
||||||
|
|
||||||
|
|
||||||
def safe_getattr(obj, name, *defargs):
|
def safe_getattr(obj, name, *defargs):
|
||||||
# type: (Any, str, str) -> object
|
# type: (Any, str, str) -> object
|
||||||
"""A getattr() that turns all exceptions into AttributeErrors."""
|
"""A getattr() that turns all exceptions into AttributeErrors."""
|
||||||
|
@ -475,3 +475,14 @@ def test_isattributedescriptor(app):
|
|||||||
assert inspect.isattributedescriptor(types.FrameType.f_locals) is True # GetSetDescriptorType # 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(datetime.timedelta.days) is True # MemberDescriptorType # NOQA
|
||||||
assert inspect.isattributedescriptor(testinstancemethod) is False # instancemethod (C-API) # 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
|
||||||
|
Loading…
Reference in New Issue
Block a user