Skip to content

Commit

Permalink
fix: Don't return properties as parameters of dataclasses (again)
Browse files Browse the repository at this point in the history
This was fixed in 5a5c03b, but broken in 82a9d57. The tests
broke as well and did not catch the regression.

Issue-232: #232
PR-248: #248
  • Loading branch information
has2k1 authored Mar 11, 2024
1 parent f314957 commit 8c48397
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/griffe/extensions/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def _dataclass_parameters(class_: Class) -> list[Parameter]:
if member.is_attribute:
member = cast(Attribute, member)

# Exclude @property and @cached_property attributes
if "property" in member.labels:
continue

# Start of keyword-only parameters.
if isinstance(member.annotation, Expr) and member.annotation.canonical_path == "dataclasses.KW_ONLY":
kw_only = True
Expand Down
12 changes: 5 additions & 7 deletions tests/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import griffe
from griffe.dataclasses import Docstring, Module
from griffe.loader import GriffeLoader
from griffe.tests import module_vtree, temporary_pypackage, temporary_visited_module, temporary_visited_package
from griffe.tests import module_vtree, temporary_pypackage, temporary_visited_package


def test_submodule_exports() -> None:
Expand Down Expand Up @@ -93,8 +93,7 @@ def test_alias_proxies() -> None:

def test_dataclass_properties() -> None:
"""Don't return properties as parameters of dataclasses."""
with temporary_visited_module(
"""
code = """
from dataclasses import dataclass
from functools import cached_property
Expand All @@ -110,11 +109,10 @@ def a(self):
@cached_property
def b(self):
return 0
""",
) as module:
"""
with temporary_visited_package("package", {"__init__.py": code}) as module:
params = module["Point"].parameters
assert "a" not in params
assert "b" not in params
assert [p.name for p in params] == ["self", "x", "y"]


@pytest.mark.parametrize(
Expand Down

0 comments on commit 8c48397

Please sign in to comment.