A community-maintained Python framework for creating mathematical animations.
fix bug in setting self.label_constructor in NumberLine.add_labels (#3015)
vahndic78bd8a22bab
diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.pyindex ededabc8e..4b5c00ad6 100644--- a/manim/mobject/graphing/number_line.py+++ b/manim/mobject/graphing/number_line.py@@ -4,7 +4,7 @@ from __future__ import annotations__all__ = ["NumberLine", "UnitInterval"]-from typing import Iterable, Sequence+from typing import Callable, Iterable, Sequenceimport numpy as np@@ -562,19 +562,18 @@ class NumberLine(Line):direction = self.label_direction if direction is None else directionbuff = self.line_to_number_buff if buff is None else bufffont_size = self.font_size if font_size is None else font_size- label_constructor = (- self.label_constructor if label_constructor is None else label_constructor- )+ if label_constructor is None:+ label_constructor = self.label_constructorlabels = VGroup()for x, label in dict_values.items():# TODO: remove this check and ability to call# this method via CoordinateSystem.add_coordinates()# must be explicitly called- if isinstance(label, str) and self.label_constructor is MathTex:+ if isinstance(label, str) and label_constructor is MathTex:label = Tex(label)else:- label = self._create_label_tex(label)+ label = self._create_label_tex(label, label_constructor)if hasattr(label, "font_size"):label.font_size = font_size@@ -588,26 +587,36 @@ class NumberLine(Line):return selfdef _create_label_tex(- self, label_tex: str | float | VMobject, **kwargs+ self,+ label_tex: str | float | VMobject,+ label_constructor: Callable | None = None,+ **kwargs,) -> VMobject:"""Checks if the label is a :class:`~.VMobject`, otherwise, creates a- label according to :attr:`label_constructor`.+ label by passing ``label_tex`` to ``label_constructor``.Parameters----------label_tex- The label to be compared against the above types.+ The label for which a mobject should be created. If the label already+ is a mobject, no new mobject is created.+ label_constructor+ Optional. A class or function returning a mobject when+ passing ``label_tex`` as an argument. If ``None`` is passed+ (the default), the label constructor from the :attr:`.label_constructor`+ attribute is used.Returns-------:class:`~.VMobject`The label."""-+ if label_constructor is None:+ label_constructor = self.label_constructorif isinstance(label_tex, VMobject):return label_texelse:- return self.label_constructor(label_tex, **kwargs)+ return label_constructor(label_tex, **kwargs)@staticmethoddef _decimal_places_from_step(step) -> int: