Skip to content

Pyreverse: Aggregations aren't filtered according to filter mode (PUB_ONLY, etc.) #10373

Closed

Description

@Julfried

Bug description

When using Pyreverse with filter modes like PUB_ONLY, relationships between classes (arrows in diagrams) are still shown even when the attributes themselves are filtered out due to visibility settings.
For example, with this code:

class P:
    pass

class A:
    x: P = P()

class B:
    __x: P = P()

And running with default settings (PUB_ONLY), the diagram shows:

classDiagram
  class A {
    x
  }
  class B {
  }
  class P {
  }
  P --* A : x
  P --* B : __x

Now __x is correctly filtered out from class B's attributes due to being private, but the relationship arrow P --* B : __x is still displayed.

When using --filter-mode=ALL, both attributes and relationships are shown correctly:

classDiagram
  class A {
    x
  }
  class B {
    __x
  }
  class P {
  }
  P --* A : x
  P --* B : __x

The relationships (arrows) should be filtered according to the same visibility rules as attributes for consistency.

Command used

pyreverse -o mmd example.py

Pylint output

Generates diagrams with relationships that don't respect the filter mode.

Expected behavior

If an attribute is filtered out due to visibility (private, protected, etc.), its relationship arrow should also be filtered out.

Pylint version

pylint 4.0.0-dev0
astroid 4.0.0a0
Python 3.13.2 (main, Feb 12 2025, 14:49:53) [MSC v.1942 64 bit (AMD64)]

Activity

  1. added
    Needs triage 📥Just created, needs acknowledgment, triage, and proper labelling
    on May 6, 2025
  2. added
    pyreverseRelated to pyreverse component
    and removed
    Needs triage 📥Just created, needs acknowledgment, triage, and proper labelling
    on May 6, 2025
  3. pavan-msys commented on May 14, 2025

    @pavan-msys
    Contributor

    Hi @Julfried

    I’m working on a fix for the issue where aggregations and associations aren’t being filtered according to the selected filter mode (PUB_ONLY, ALL, etc.) in Pyreverse.

    To fix this, I added a check in the extract_relationships() method to filter out aggregations and associations based on visibility before adding them to the diagram. I used self.show_attr(name) to handle this filtering.

    Before I submit a PR, I wanted to check if this is the right approach. Does this look good, or is there something else I should consider for filtering these relationships based on the filter mode?

  4. added this to the 3.3.8 milestone on May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions