-
-
Notifications
You must be signed in to change notification settings - Fork 63
bug: property and cached_property of dataclasses are class parameters #232
Copy link
Copy link
Closed
Description
Description of the bug
A @property or @cached_property of dataclass is taken to be a class parameter
To Reproduce
sample.py
from functools import cached_property
from dataclasses import dataclass
class PointA:
def __init__(self, x: float, y: float):
self.x = x
self.y = y
@property
def distance(self):
return 0
class PointB:
def __init__(self, x: float, y: float):
self.x = x
self.y = y
@cached_property
def distance(self):
return 0
@dataclass
class PointC:
x: float
y: float
@property
def distance(self):
return 0
@dataclass
class PointD:
x: float
y: float
@cached_property
def distance(self):
return 0Demo code
import griffe
def print_parameters(path):
"""
Print class/method and a list of its parameters
"""
obj = griffe.load(path)
params = ", ".join(p.name for p in obj.parameters if p.name != "self")
print(f"{obj.name}({params})")
print_parameters("sample.PointA")
print_parameters("sample.PointB")
print_parameters("sample.PointC")
print_parameters("sample.PointD")Output
PointA(x, y)
PointB(x, y)
PointC(x, y, distance)
PointD(x, y, distance)
Expected behavior
The parameters in all four cases should be (x, y).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels