Skip to content

Commit

Permalink
fix: Move setter and deleter to Attribute class instead of `Fun…
Browse files Browse the repository at this point in the history
…ction`, since that's how properties are instantiated

Issue-311: #311
  • Loading branch information
pawamoy committed Aug 11, 2024
1 parent 6644fe5 commit 309c6e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/_griffe/agents/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
13 changes: 9 additions & 4 deletions src/_griffe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 309c6e3

Please # to comment.