33from autofit .mapper .model_object import ModelObject
44
55
6- class Constant (ModelObject , Number ):
6+ class Constant (float , ModelObject ):
7+ def __new__ (cls , value : float , id_ = None ):
8+ obj = super ().__new__ (cls , value )
9+ return obj
10+
711 def __init__ (self , value : float , id_ = None ):
812 """
913 Represents a constant value in a model.
@@ -18,63 +22,27 @@ def __init__(self, value: float, id_=None):
1822 value
1923 The constant value.
2024 """
21- super ().__init__ (
22- id_ = id_ ,
23- )
25+ if isinstance (value , Constant ):
26+ value = value .value
27+
28+ ModelObject .__init__ (self , id_ = id_ )
2429 self .value = value
2530
2631 def __str__ (self ):
2732 return str (self .value )
2833
2934 def __eq__ (self , other ):
30- if isinstance (other , (int , float )):
31- return self .value == other
32- return super ().__eq__ (other )
35+ if isinstance (other , ModelObject ):
36+ return ModelObject .__eq__ (self , other )
37+ return self .value == other
38+
39+ def __ne__ (self , other ):
40+ if isinstance (other , ModelObject ):
41+ return ModelObject .__ne__ (self , other )
42+ return self .value != other
3343
3444 def __hash__ (self ):
3545 return hash (self .id )
3646
3747 def dict (self ):
3848 return {"type" : "Constant" , "value" : self .value }
39-
40- def __add__ (self , other ):
41- return self .value + other
42-
43- def __sub__ (self , other ):
44- return self .value - other
45-
46- def __mul__ (self , other ):
47- return self .value * other
48-
49- def __truediv__ (self , other ):
50- return self .value / other
51-
52- def __pow__ (self , other ):
53- return self .value ** other
54-
55- def __radd__ (self , other ):
56- return other + self .value
57-
58- def __rsub__ (self , other ):
59- return other - self .value
60-
61- def __rmul__ (self , other ):
62- return other * self .value
63-
64- def __rtruediv__ (self , other ):
65- return other / self .value
66-
67- def __rpow__ (self , other ):
68- return other ** self .value
69-
70- def __lt__ (self , other ):
71- return self .value < other
72-
73- def __le__ (self , other ):
74- return self .value <= other
75-
76- def __gt__ (self , other ):
77- return self .value > other
78-
79- def __ge__ (self , other ):
80- return self .value >= other
0 commit comments