Skip to content

docs: explain why explicit base __init__ calls are required - #5068

Closed
authyx wants to merge 1 commit into
ManimCommunity:mainfrom
authyx:docs/clarify-explicit-base-init-in-axes
Closed

authyx wants to merge 1 commit into
ManimCommunity:mainfrom
authyx:docs/clarify-explicit-base-init-in-axes

Conversation

@authyx

@authyx authyx commented Oct 15, 2026 •

Copy link
Copy Markdown

Overview

Comment-only change. Adds explanatory notes next to two intentional explicit base __init__ calls so they are not "simplified" to super().__init__() in future cleanups.

Motivated by #5067, which proposed replacing every Parent.__init__(self, ...) with super().__init__(...). Investigation there showed the pattern is intentional at the real call sites, and a mechanical replacement would break things. This PR documents why, so the question does not come up again.

Details

manim/camera/mapping_camera.py — SplitScreenCamera

Camera.__init__(self, **kwargs)   # to set attributes such as pixel_width
...
half_width = math.ceil(self.pixel_width / 2)   # requires pixel_width set above

The explicit call must run before super().__init__(...). Replacing it with super() would dispatch to OldMultiCamera (which expects positional camera tuples) and pixel_width would never be set, raising AttributeError.

manim/mobject/graphing/coordinate_systems.py — Axes

class Axes(VGroup, CoordinateSystem, metaclass=ConvertToOpenGL):
    def __init__(self, ...):
        VGroup.__init__(self, **kwargs)
        CoordinateSystem.__init__(self, x_range, y_range, x_length, y_length)

VGroup and CoordinateSystem are non-cooperative bases, so super().__init__() follows only one MRO branch and skips CoordinateSystem.__init__ entirely, leaving the instance half-initialized. Minimal repro:

class CoordinateSystem:
    def __init__(self, *a, **k): self.cs_init = True
class VGroup:
    def __init__(self, *a, **k): self.vg_init = True

class Axes(VGroup, CoordinateSystem):
    def __init__(self, *a, **k):
        super().__init__(*a, **k)

a = Axes()   # a.vg_init == True, a.cs_init == False

Checklist

Closes nothing on its own — left open pending #5067 direction.

Add explanatory comments next to the two intentional explicit base
__init__ calls, to prevent them being re-reported / "simplified" to
super().__init__() in future cleanups (see #5067).

- `SplitScreenCamera`: Camera.__init__ is called first so
  self.pixel_width exists before half_width is computed; super() would
  dispatch to OldMultiCamera and raise AttributeError.
- `Axes`: VGroup and CoordinateSystem are non-cooperative bases, so
  super() would follow only one MRO branch and skip
  CoordinateSystem.__init__, leaving the instance half-initialized.

Comment-only change; no behaviour modified.
@GniLudio

Copy link
Copy Markdown
Contributor

good-first-issue's should be kept for humans.

@GniLudio GniLudio closed this Oct 15, 2026
@authyx

authyx commented Oct 16, 2026

Copy link
Copy Markdown
Author

@GniLudio still a good-first-issue?

@GniLudio

Copy link
Copy Markdown
Contributor

@GniLudio still a good-first-issue?

You are welcome to contribute to manim, but I would recommend you to avoid relying on AI-agents too much for your first contribution, so that you can familiarize yourself with the codebase a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace ParentClass.__init__(self with super().__init__

2 participants