manim icon indicating copy to clipboard operation
manim copied to clipboard

config: return ManimColor instance from background_color property

Open Drunsdo opened this issue 5 months ago • 2 comments

Source

manim/_config/utils.py, line 1193 (as of HEAD ):

# TODO: This was parsed before maybe add ManimColor(val), but results in circular import
    @property
    def background_color(self) -> ManimColor:
        """Background color of the scene (-c)."""
        return self._d["background_color"]

Problem

The background_color property is type-annotated as ManimColor, but the underlying value stored in self._d is not wrapped in a ManimColor instance. The natural fix, return ManimColor(self._d["background_color"]), is blocked by a circular import between _config/utils.py and the ManimColor definition.

The mismatch between the annotation and the runtime value can mislead callers that rely on ManimColor methods being available on the returned object.

Suggested approaches

  • Lazy import of ManimColor inside the getter.
  • Restructure the import graph so _config/utils.py can import ManimColor at module level.
  • Audit other config properties that may have the same gap (e.g. other color-typed config values).

Drunsdo avatar Jun 12 '26 16:06 Drunsdo

Hi, I’d like to take this one. Could you assign it to me?

pranjalimahatme avatar Oct 18 '26 10:10 pranjalimahatme

I looked into this and it seems the circular import mentioned in the TODO no longer exists: manim/_config/utils.py already imports ManimColor at module level (line 32), and the background_color setter already wraps every value in ManimColor(...).

I checked the getter's return type through every path I could find (default config, tempconfig, config.update(dict), config.update(other_config), config["background_color"] = ..., and config.copy()), and it is always a ManimColor instance. background_color also seems to be the only colour-typed config option, so there's nothing else to audit.

So I'd suggest a small PR that:

  • removes the outdated TODO comment, and
  • adds a regression test in tests/test_config.py asserting that config.background_color is a ManimColor on all these paths.

I'll open a PR for this.

pranjalimahatme avatar Oct 27 '26 09:10 pranjalimahatme