Skip to content

Commit

Permalink
Update writer logic to also add properties to the diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
Julfried committed Oct 30, 2024
1 parent c1ecb1a commit a380c46
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pylint/pyreverse/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,27 @@ def get_package_properties(self, obj: PackageEntity) -> NodeProperties:

def get_class_properties(self, obj: ClassEntity) -> NodeProperties:
"""Get label and shape for classes."""
attrs = obj.attrs if not self.config.only_classnames else None
methods = obj.methods if not self.config.only_classnames else None

if attrs and hasattr(obj.node, "properties"):
formatted_attrs = []
property_names = {prop.name for prop in obj.node.properties}

for attr in attrs:
name = attr.split(":")[0].strip()
if name in property_names:
# Get type from instance_attrs_type
prop_type = obj.node.instance_attrs_type.get(name, ["Unknown"])[0]
formatted_attrs.append(f"{name} «property»: {prop_type}")
else:
formatted_attrs.append(attr)
attrs = formatted_attrs

properties = NodeProperties(
label=obj.title,
attrs=obj.attrs if not self.config.only_classnames else None,
methods=obj.methods if not self.config.only_classnames else None,
attrs=attrs,
methods=methods,
fontcolor="red" if is_exception(obj.node) else "black",
color=self.get_shape_color(obj) if self.config.colorized else "black",
)
Expand Down

0 comments on commit a380c46

Please sign in to comment.