Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
chopan050 opened this issue May 12, 2024 · 0 comments · Fixed by #3756
Closed

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

chopan050 opened this issue May 12, 2024 · 0 comments · Fixed by #3756

Comments

@chopan050
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

Successfully merging a pull request may close this issue.

1 participant