44
55__all__ = ["DecimalNumber" , "Integer" , "Variable" ]
66
7- from collections .abc import Sequence
87from typing import Any
98
109import numpy as np
10+ from typing_extensions import Self
1111
1212from manim import config
1313from manim .constants import *
1616from manim .mobject .text .text_mobject import Text
1717from manim .mobject .types .vectorized_mobject import VMobject
1818from manim .mobject .value_tracker import ValueTracker
19+ from manim .typing import Point3DLike
1920
20- string_to_mob_map = {}
21-
22- __all__ = ["DecimalNumber" , "Integer" , "Variable" ]
21+ string_to_mob_map : dict [str , VMobject ] = {}
2322
2423
2524class DecimalNumber (VMobject , metaclass = ConvertToOpenGL ):
@@ -86,19 +85,19 @@ def __init__(
8685 self ,
8786 number : float = 0 ,
8887 num_decimal_places : int = 2 ,
89- mob_class : VMobject = MathTex ,
88+ mob_class : type [ SingleStringMathTex ] = MathTex ,
9089 include_sign : bool = False ,
9190 group_with_commas : bool = True ,
9291 digit_buff_per_font_unit : float = 0.001 ,
9392 show_ellipsis : bool = False ,
9493 unit : str | None = None , # Aligned to bottom unless it starts with "^"
9594 unit_buff_per_font_unit : float = 0 ,
9695 include_background_rectangle : bool = False ,
97- edge_to_fix : Sequence [ float ] = LEFT ,
96+ edge_to_fix : Point3DLike = LEFT ,
9897 font_size : float = DEFAULT_FONT_SIZE ,
9998 stroke_width : float = 0 ,
10099 fill_opacity : float = 1.0 ,
101- ** kwargs ,
100+ ** kwargs : Any ,
102101 ):
103102 super ().__init__ (** kwargs , fill_opacity = fill_opacity , stroke_width = stroke_width )
104103 self .number = number
@@ -137,12 +136,13 @@ def __init__(
137136 self .init_colors ()
138137
139138 @property
140- def font_size (self ):
139+ def font_size (self ) -> float :
141140 """The font size of the tex mobject."""
142- return self .height / self .initial_height * self ._font_size
141+ return_value : float = self .height / self .initial_height * self ._font_size
142+ return return_value
143143
144144 @font_size .setter
145- def font_size (self , font_val ) :
145+ def font_size (self , font_val : float ) -> None :
146146 if font_val <= 0 :
147147 raise ValueError ("font_size must be greater than 0." )
148148 elif self .height > 0 :
@@ -153,7 +153,7 @@ def font_size(self, font_val):
153153 # font_size does not depend on current size.
154154 self .scale (font_val / self .font_size )
155155
156- def _set_submobjects_from_number (self , number ) :
156+ def _set_submobjects_from_number (self , number : float ) -> None :
157157 self .number = number
158158 self .submobjects = []
159159
@@ -197,12 +197,12 @@ def _set_submobjects_from_number(self, number):
197197 self .unit_sign .align_to (self , UP )
198198
199199 # track the initial height to enable scaling via font_size
200- self .initial_height = self .height
200+ self .initial_height : float = self .height
201201
202202 if self .include_background_rectangle :
203203 self .add_background_rectangle ()
204204
205- def _get_num_string (self , number ) :
205+ def _get_num_string (self , number : float | complex ) -> str :
206206 if isinstance (number , complex ):
207207 formatter = self ._get_complex_formatter ()
208208 else :
@@ -215,17 +215,22 @@ def _get_num_string(self, number):
215215
216216 return num_string
217217
218- def _string_to_mob (self , string : str , mob_class : VMobject | None = None , ** kwargs ):
218+ def _string_to_mob (
219+ self ,
220+ string : str ,
221+ mob_class : type [SingleStringMathTex ] | None = None ,
222+ ** kwargs : Any ,
223+ ) -> VMobject :
219224 if mob_class is None :
220225 mob_class = self .mob_class
221226
222227 if string not in string_to_mob_map :
223228 string_to_mob_map [string ] = mob_class (string , ** kwargs )
224229 mob = string_to_mob_map [string ].copy ()
225- mob .font_size = self ._font_size
230+ mob .font_size = self ._font_size # type: ignore[attr-defined]
226231 return mob
227232
228- def _get_formatter (self , ** kwargs ) :
233+ def _get_formatter (self , ** kwargs : Any ) -> str :
229234 """
230235 Configuration is based first off instance attributes,
231236 but overwritten by any kew word argument. Relevant
@@ -258,7 +263,7 @@ def _get_formatter(self, **kwargs):
258263 ],
259264 )
260265
261- def _get_complex_formatter (self ):
266+ def _get_complex_formatter (self ) -> str :
262267 return "" .join (
263268 [
264269 self ._get_formatter (field_name = "0.real" ),
@@ -267,7 +272,7 @@ def _get_complex_formatter(self):
267272 ],
268273 )
269274
270- def set_value (self , number : float ):
275+ def set_value (self , number : float ) -> Self :
271276 """Set the value of the :class:`~.DecimalNumber` to a new number.
272277
273278 Parameters
@@ -304,10 +309,10 @@ def set_value(self, number: float):
304309 self .init_colors ()
305310 return self
306311
307- def get_value (self ):
312+ def get_value (self ) -> float :
308313 return self .number
309314
310- def increment_value (self , delta_t = 1 ) :
315+ def increment_value (self , delta_t : float = 1 ) -> None :
311316 self .set_value (self .get_value () + delta_t )
312317
313318
@@ -333,7 +338,7 @@ def __init__(
333338 ) -> None :
334339 super ().__init__ (number = number , num_decimal_places = num_decimal_places , ** kwargs )
335340
336- def get_value (self ):
341+ def get_value (self ) -> int :
337342 return int (np .round (super ().get_value ()))
338343
339344
@@ -444,9 +449,9 @@ def __init__(
444449 self ,
445450 var : float ,
446451 label : str | Tex | MathTex | Text | SingleStringMathTex ,
447- var_type : DecimalNumber | Integer = DecimalNumber ,
452+ var_type : type [ DecimalNumber | Integer ] = DecimalNumber ,
448453 num_decimal_places : int = 2 ,
449- ** kwargs ,
454+ ** kwargs : Any ,
450455 ):
451456 self .label = MathTex (label ) if isinstance (label , str ) else label
452457 equals = MathTex ("=" ).next_to (self .label , RIGHT )
0 commit comments