Skip to content

Using Swap on two Mobjects in a group can cause self.remove to not work on that group #4210

Open
@JedGrabman

Description

@JedGrabman

Description of bug / unexpected behavior

After using Swap on two Mobjects in the same Group, I have found that attempts to use self.remove to remove the Group sometimes fail and the Group remains visible

Expected behavior

Running self.remove on a Group should cause that Group to no longer be visible and preceding Swap commands should not affect this.

How to reproduce the issue

Code for reproducing the problem
class SwapTest(Scene):
    def construct(self):
        text_a = Text("A").move_to([1, 0, 0])
        text_b = Text("B").move_to([2, 0, 0])
        text_group = Group(*[text_a, text_b])
        self.play(FadeIn(text_group))
        self.play(Swap(text_a, text_b))
        # Note that uncommenting the following command causes the later self.remove to work as expected
        # self.play(text_group.animate.move_to([0,0,0]))
        self.remove(text_group)
        self.wait(1)

Additional media files

SwapTest.mp4

When uncommenting the specified line, we see self.remove(text_group) working as expected

SwapTest.mp4

System specifications

System Details
  • OS Microsoft Windows 11 Home
  • Python version (python --version) - Python 3.11.4
  • Installed modules (provide output from pip list):
WARNING: Ignoring invalid distribution ~ip (C:\Python311\Lib\site-packages)
WARNING: Ignoring invalid distribution ~umpy (C:\Python311\Lib\site-packages)
Package            Version
------------------ -----------
av                 13.1.0
beautifulsoup4     4.13.3
certifi            2024.12.14
cftime             1.6.4.post1
click              8.1.7
cloudpickle        3.1.0
cloup              3.0.5
colorama           0.4.6
dask               2024.12.1
decorator          5.1.1
fsspec             2024.12.0
glcontext          3.0.0
importlib_metadata 8.5.0
iniconfig          2.0.0
isosurfaces        0.1.2
locket             1.0.0
manim              0.19.0
ManimPango         0.5.0
mapbox_earcut      1.0.2
markdown-it-py     3.0.0
mdurl              0.1.2
moderngl           5.11.1
moderngl-window    3.1.1
multipledispatch   1.0.0
netCDF4            1.7.2
networkx           3.3
numpy              2.2.4
packaging          24.2
pandas             2.2.3
partd              1.4.2
pillow             10.4.0
pip                25.0.1
pluggy             1.5.0
portalocker        3.1.1
pycairo            1.26.1
pydub              0.25.1
pyglet             2.0.17
pyglm              2.8.1
Pygments           2.18.0
pyrr               0.10.3
pytest             8.3.4
python-dateutil    2.9.0.post0
python-sat         1.8.dev14
pytz               2024.2
pywin32            308
PyYAML             6.0.2
rich               13.7.1
scipy              1.14.0
screeninfo         0.8.1
setuptools         78.1.0
six                1.17.0
skia-pathops       0.8.0.post1
soupsieve          2.6
srt                3.5.3
svgelements        1.9.6
toolz              1.0.0
tqdm               4.66.5
typing_extensions  4.12.2
tzdata             2024.2
watchdog           4.0.2
wheel              0.45.1
xarray             2025.1.1
zipp               3.21.0

Additional comments

self.remove(*text_group) (with the unpacking operator *) works as expected

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