From 5a5c03b38366049f19fc2b65f09153e7df5748ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 8 Feb 2024 16:16:26 +0100 Subject: [PATCH] fix: Don't return properties as parameters of dataclasses Issue #232: https://github.com/mkdocstrings/griffe/issues/232 --- src/griffe/dataclasses.py | 1 + tests/test_dataclasses.py | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/griffe/dataclasses.py b/src/griffe/dataclasses.py index 0820999b..f50456cc 100644 --- a/src/griffe/dataclasses.py +++ b/src/griffe/dataclasses.py @@ -1566,6 +1566,7 @@ def parameters(self) -> Parameters: *[ Parameter(attr.name, annotation=attr.annotation, default=attr.value) for attr in self.attributes.values() + if "property" not in attr.labels ], ) return Parameters() diff --git a/tests/test_dataclasses.py b/tests/test_dataclasses.py index f85f8671..00ec8579 100644 --- a/tests/test_dataclasses.py +++ b/tests/test_dataclasses.py @@ -7,7 +7,7 @@ import griffe from griffe.dataclasses import Docstring, Module from griffe.loader import GriffeLoader -from griffe.tests import module_vtree, temporary_pypackage +from griffe.tests import module_vtree, temporary_pypackage, temporary_visited_module def test_submodule_exports() -> None: @@ -86,3 +86,29 @@ def test_alias_proxies() -> None: for name in cls.all_members: if not name.startswith("_") or name.startswith("__"): assert name in alias_members + + +def test_dataclass_parameters() -> None: + """Don't return properties as parameters of dataclasses.""" + with temporary_visited_module( + """ + from dataclasses import dataclass + from functools import cached_property + + @dataclass + class Point: + x: float + y: float + + @property + def a(self): + return 0 + + @cached_property + def b(self): + return 0 + """, + ) as module: + params = module["Point"].parameters + assert "a" not in params + assert "b" not in params