Skip to content

Add missing mobject method chaining - #4913

Merged
behackl merged 12 commits into
ManimCommunity:mainfrom
GniLudio:add-missing-method-chaining
Aug 7, 2026
Merged

Add missing mobject method chaining#4913
behackl merged 12 commits into
ManimCommunity:mainfrom
GniLudio:add-missing-method-chaining

Conversation

@GniLudio

@GniLudio GniLudio commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Overview: What does this pull request change?

Adds missing method chaining for mobject methods.

  • Adds -> Self type annotation.
  • Changes -> [MobjectClass] to -> Self.
  • Adds return self for updater-methods that returned nothing.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Comment thread manim/mobject/graph.py Fixed
Comment thread manim/mobject/opengl/opengl_surface.py Fixed
@GniLudio

GniLudio commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

The tests don't fail for me locally: (after installing the typst package)

980 passed, 2 skipped, 6 xfailed, 2 xpassed, 27 warnings in 285.99s (0:04:45)

@behackl

behackl commented Aug 5, 2026

Copy link
Copy Markdown
Member

Cool, thank you!

Looks like you are running into an issue with some of our doctests; from the ubuntu / Python 3.13 CI:

______________ [doctest] manim.mobject.mobject.Mobject.align_data ______________
[gw0] linux -- Python 3.13.14 /home/runner/work/manim/manim/.venv/bin/python3
2983     compatible before transformation.
2984 
2985 Examples
2986 --------
2987 ::
2988 
2989     >>> from manim import Rectangle, Line, ORIGIN, RIGHT
2990     >>> rect = Rectangle(width=4.0, height=2.0, grid_xstep=1.0, grid_ystep=0.5)
2991     >>> line = Line(start=ORIGIN,end=RIGHT)
2992     >>> line.align_data(rect)
Expected nothing
Got:
    Line

The windows CIs fail with a weird path issue, I can take a closer look at that later. 🧐

@GniLudio

GniLudio commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Also, I noticed that OpenGLVMobject.add_points_as_corners returns the points it received.

def add_points_as_corners(self, points):
    ...
    return points

I didn't change that as it would change the return type, but returning self would definitely make more sense.
The corresponding VMobject method returns self.

@nikolajmunk

Copy link
Copy Markdown
Contributor

A thought: Some of these methods are nasty when used in an .animate chain. Something like mob.animate.insert(3, new_mob) will throw a ValueError: zip() argument 2 is shorter than argument 1.

This is nothing against this PR - I note that Mobject.add already returns self and suffers from the exact same issue - but it maybe raises the question of "is this fine and intended behavior?". I could imagine a newbie getting burned on trying to animate all sorts of weird stuff. OTOH I don't have a good idea of how to address it.

@behackl behackl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! I've pushed one commit to fix some issues with CI, the docbuild is apparently failing now -- don't think it is generally flaky right now so might be due to changes made on this PR. Some comments:

  • I think it is fine to technically support chaining, even if some methods are not suitable for the .animate syntax. This is a somewhat orthogonal problem that we can think about; perhaps we can decorate non-suitable methods to let the AnimationBuilder fail or so... but it doesn't matter for now.
  • VMobject.align_points has an "overly eager" early return which currently doesn't return self (you fixed it for OpenGLVMobject).
  • Plus I found two inline functions, see comments below, where the change should be reverted.

I'd be in favour of changing the output of OpenGLVMobject.add_points_as_corners as well, only makes sense to clean this up. I'll need to do a somewhat more rigorous review round later, but for now this is it. Thanks again for your efforts!

Comment thread manim/mobject/vector_field.py Outdated
Comment thread manim/mobject/vector_field.py Outdated
@nikolajmunk

Copy link
Copy Markdown
Contributor

@behackl

I think it is fine to technically support chaining, even if some methods are not suitable for the .animate syntax. This is a somewhat orthogonal problem that we can think about; perhaps we can decorate non-suitable methods to let the AnimationBuilder fail or so... but it doesn't matter for now.

Agree! There already exists some precedent for disallowing .animate chaining on methods which have an override_animate, so this seems like a good topic for a separate discussion.

@GniLudio

GniLudio commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

I've pushed one commit to fix some issues with CI.

Some of the things you reverted were suggested to me by pre-commit run --all-files.

Validate Python..........................................................Passed
trim trailing whitespace.................................................Passed
mixed line ending........................................................Passed
fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook

Fixing docs/source/conduct.md

Validate pyproject.toml..................................................Passed
codespell................................................................Passed
ruff lint................................................................Passed
ruff format..............................................................Passed
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

manim\utils\file_ops.py:200: error: Unused "type: ignore" comment  [unused-ignore]
Found 1 error in 1 file (checked 168 source files)

@behackl

behackl commented Aug 6, 2026

Copy link
Copy Markdown
Member

Some of the things you reverted were suggested to me by pre-commit run --all-files.

Oh, that is very weird: in particular the change with the symlink should definitely not happen. We should probably cleanup our pre-commit setup a bit.

behackl added 2 commits August 7, 2026 20:51
…chaining

# Conflicts:
#	manim/mobject/graphing/probability.py
#	manim/mobject/table.py

@behackl behackl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved the conflicts + pushed an additional commit fixing three more missing returns. Looks all good for me now, happy to get this merged once the pipeline passes.

Thanks again for your efforts!

@behackl behackl added the enhancement Additions and improvements in general label Aug 7, 2026
@behackl
behackl merged commit c591dae into ManimCommunity:main Aug 7, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Additions and improvements in general

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants