config: return ManimColor instance from background_color property
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
ManimColorinside the getter. - Restructure the import graph so
_config/utils.pycan importManimColorat module level. - Audit other config properties that may have the same gap (e.g. other color-typed config values).
Hi, I’d like to take this one. Could you assign it to me?
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.pyasserting thatconfig.background_coloris aManimColoron all these paths.
I'll open a PR for this.