Skip to content

Commit a380c46

Browse files
committed
Update writer logic to also add properties to the diagram
1 parent c1ecb1a commit a380c46

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

pylint/pyreverse/writer.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,27 @@ def get_package_properties(self, obj: PackageEntity) -> NodeProperties:
169169

170170
def get_class_properties(self, obj: ClassEntity) -> NodeProperties:
171171
"""Get label and shape for classes."""
172+
attrs = obj.attrs if not self.config.only_classnames else None
173+
methods = obj.methods if not self.config.only_classnames else None
174+
175+
if attrs and hasattr(obj.node, "properties"):
176+
formatted_attrs = []
177+
property_names = {prop.name for prop in obj.node.properties}
178+
179+
for attr in attrs:
180+
name = attr.split(":")[0].strip()
181+
if name in property_names:
182+
# Get type from instance_attrs_type
183+
prop_type = obj.node.instance_attrs_type.get(name, ["Unknown"])[0]
184+
formatted_attrs.append(f"{name} «property»: {prop_type}")
185+
else:
186+
formatted_attrs.append(attr)
187+
attrs = formatted_attrs
188+
172189
properties = NodeProperties(
173190
label=obj.title,
174-
attrs=obj.attrs if not self.config.only_classnames else None,
175-
methods=obj.methods if not self.config.only_classnames else None,
191+
attrs=attrs,
192+
methods=methods,
176193
fontcolor="red" if is_exception(obj.node) else "black",
177194
color=self.get_shape_color(obj) if self.config.colorized else "black",
178195
)

0 commit comments

Comments
 (0)