From 309c6e34aded516dcfeab0dd81c2fbcecd2691ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sun, 11 Aug 2024 14:32:41 +0200 Subject: [PATCH] fix: Move `setter` and `deleter` to `Attribute` class instead of `Function`, since that's how properties are instantiated Issue-311: https://github.com/mkdocstrings/griffe/issues/311 --- src/_griffe/agents/visitor.py | 2 +- src/_griffe/models.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/_griffe/agents/visitor.py b/src/_griffe/agents/visitor.py index 8cc6aae3..8f57ed9d 100644 --- a/src/_griffe/agents/visitor.py +++ b/src/_griffe/agents/visitor.py @@ -423,7 +423,7 @@ def handle_function(self, node: ast.AsyncFunctionDef | ast.FunctionDef, labels: if overload: self.current.overloads[function.name].append(function) elif property_function: - base_property: Function = self.current.members[node.name] # type: ignore[assignment] + base_property: Attribute = self.current.members[node.name] # type: ignore[assignment] if property_function == "setter": base_property.setter = function base_property.labels.add("writable") diff --git a/src/_griffe/models.py b/src/_griffe/models.py index 364f183b..0d124822 100644 --- a/src/_griffe/models.py +++ b/src/_griffe/models.py @@ -1741,12 +1741,13 @@ def __init__( """The function return type annotation.""" self.decorators: list[Decorator] = decorators or [] """The function decorators.""" - self.setter: Function | None = None - """The setter linked to this function (property).""" - self.deleter: Function | None = None - """The deleter linked to this function (property).""" self.overloads: list[Function] | None = None """The overloaded signatures of this function.""" + # YORE: Bump 1: Remove block. + self.setter: Function | None = None + """Deprecated. See [Attribute.setter][griffe.Attribute.setter].""" + self.deleter: Function | None = None + """Deprecated. See [Attribute.deleter][griffe.Attribute.deleter].""" for parameter in self.parameters: parameter.function = self @@ -1797,6 +1798,10 @@ def __init__( """The attribute value.""" self.annotation: str | Expr | None = annotation """The attribute type annotation.""" + self.setter: Function | None = None + """The setter linked to this property.""" + self.deleter: Function | None = None + """The deleter linked to this property.""" def as_dict(self, **kwargs: Any) -> dict[str, Any]: """Return this function's data as a dictionary.