Skip to content

Commit bc3c75a

Browse files
committed
fix: Handle get/set descriptor objects as properties during dynamic analysis
Issue-354: #354
1 parent 425aece commit bc3c75a

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/_griffe/agents/inspector.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ def inspect_property(self, node: ObjectNode) -> None:
408408
"""
409409
self.handle_function(node, {"property"})
410410

411+
def inspect_getset_descriptor(self, node: ObjectNode) -> None:
412+
"""Inspect a get/set descriptor.
413+
414+
Parameters:
415+
node: The node to inspect.
416+
"""
417+
self.handle_function(node, {"property"})
418+
411419
def handle_function(self, node: ObjectNode, labels: set | None = None) -> None:
412420
"""Handle a function.
413421

src/_griffe/agents/nodes/runtime.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import inspect
66
import sys
77
from functools import cached_property
8+
from types import GetSetDescriptorType
89
from typing import TYPE_CHECKING, Any, ClassVar
910

1011
from _griffe.enumerations import ObjectKind
@@ -130,6 +131,8 @@ def kind(self) -> ObjectKind:
130131
return ObjectKind.METHOD_DESCRIPTOR
131132
if self.is_function:
132133
return ObjectKind.FUNCTION
134+
if self.is_getset_descriptor:
135+
return ObjectKind.GETSET_DESCRIPTOR
133136
if self.is_property:
134137
return ObjectKind.PROPERTY
135138
return ObjectKind.ATTRIBUTE
@@ -169,6 +172,11 @@ def is_coroutine(self) -> bool:
169172
"""Whether this node's object is a coroutine."""
170173
return inspect.iscoroutinefunction(self.obj)
171174

175+
@cached_property
176+
def is_getset_descriptor(self) -> bool:
177+
"""Whether this node's object is a get/set descriptor."""
178+
return isinstance(self.obj, GetSetDescriptorType)
179+
172180
@cached_property
173181
def is_property(self) -> bool:
174182
"""Whether this node's object is a property."""

src/_griffe/enumerations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class ObjectKind(str, Enum):
173173
"""Built-in functions."""
174174
CACHED_PROPERTY = "cached_property"
175175
"""Cached properties."""
176+
GETSET_DESCRIPTOR = "getset_descriptor"
177+
"""Get/set descriptors."""
176178
PROPERTY = "property"
177179
"""Properties."""
178180
ATTRIBUTE = "attribute"

0 commit comments

Comments
 (0)