Skip to content

VGroup cannot have a Mobject as a child, but VMobject can #3755

@chopan050

Description

@chopan050

Description of bug / unexpected behavior

Mobject methods like add() assert that all the values passed are also instances of Mobject, before adding them as children (into Mobject.submobjects).

VGroup overrides add() to go even further, by asserting that the values are instances of the VMobject subclass, being more restrictive than the original assertion.

However, the VMobject class itself does NOT have that assertion, so you can actually add a Mobject to it which is not a VMobject.

Therefore, this is legal:

Circle().add(Mobject())

but this raises a TypeError:

VGroup().add(Mobject())

A direct consequence of this is that this is allowed:

circle = Circle()
circle.add(Mobject())
group = VGroup()
group.add(circle)

creating a VGroup which contains a Mobject in its family, even though it's not a direct child / submobject.

Expected behavior

The VMobject itself should assert that only VMobjects can be added to it. Adding a Mobject to a VMobject such as Circle should be illegal and also throw a TypeError. By doing this, VGroup would automatically do the assertion as well, as it's a subclass of VMobject.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions