Skip to content

Commit a707767

Browse files
committed
Update writer logic to also add properties to the diagram
1 parent 9962519 commit a707767

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
@@ -171,10 +171,27 @@ def get_package_properties(self, obj: PackageEntity) -> NodeProperties:
171171

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

0 commit comments

Comments
 (0)