44#
55
66
7+ from typing import Any
8+
9+
710class ConfigurableValueError (ValueError ):
811 def __init__ (self , message , prefix = None ):
912 self .message = f"{ prefix } : { message } " if prefix else message
@@ -13,8 +16,8 @@ def __init__(self, message, prefix=None):
1316class BaseValue :
1417 def __init__ (
1518 self ,
16- description = "No description available" ,
17- default_value = None ,
19+ description : str = "No description available" ,
20+ default_value : Any | None = None ,
1821 ) -> None :
1922 self .default_value = default_value
2023 self .description = description
@@ -45,10 +48,10 @@ def __str__(self) -> str:
4548class NumericalValue (BaseValue ):
4649 def __init__ (
4750 self ,
48- value_type = float ,
49- choices = (),
50- min = None ,
51- max = None ,
51+ value_type : Any = float ,
52+ choices : tuple [ Any , ...] = (),
53+ min : Any | None = None ,
54+ max : Any | None = None ,
5255 ** kwargs ,
5356 ) -> None :
5457 super ().__init__ (** kwargs )
@@ -57,7 +60,7 @@ def __init__(
5760 self .max = max
5861 self .value_type = value_type
5962
60- def from_str (self , value ) :
63+ def from_str (self , value : str ) -> Any :
6164 return self .value_type (value )
6265
6366 def validate (self , value ):
@@ -102,18 +105,18 @@ def __str__(self) -> str:
102105class StringValue (BaseValue ):
103106 def __init__ (
104107 self ,
105- choices = (),
106- description = "No description available" ,
107- default_value = "" ,
108- ):
108+ choices : tuple [ Any , ...] = (),
109+ description : str = "No description available" ,
110+ default_value : str = "" ,
111+ ) -> None :
109112 super ().__init__ (description , default_value )
110113 self .choices = choices
111114 for choice in self .choices :
112115 if not isinstance (choice , str ):
113116 msg = f"Incorrect option in choice list - { choice } ."
114117 raise ValueError (msg )
115118
116- def from_str (self , value ) :
119+ def from_str (self , value : str ) -> str :
117120 return value
118121
119122 def validate (self , value ):
@@ -147,7 +150,7 @@ class BooleanValue(BaseValue):
147150 def __init__ (self , ** kwargs ) -> None :
148151 super ().__init__ (** kwargs )
149152
150- def from_str (self , value ) :
153+ def from_str (self , value : str ) -> bool :
151154 return value == "YES" or value == "True"
152155
153156 def validate (self , value ):
@@ -166,14 +169,14 @@ def validate(self, value):
166169class ListValue (BaseValue ):
167170 def __init__ (
168171 self ,
169- value_type = None ,
170- description = "No description available" ,
171- default_value = [],
172+ value_type : Any | None = None ,
173+ description : str = "No description available" ,
174+ default_value : list [ Any ] = [],
172175 ) -> None :
173176 super ().__init__ (description , default_value )
174177 self .value_type = value_type
175178
176- def from_str (self , value ) :
179+ def from_str (self , value : str ) -> list [ Any ] :
177180 try :
178181 floats = [float (i ) for i in value .split ()]
179182 try :
@@ -224,7 +227,7 @@ class DictValue(BaseValue):
224227 def __init__ (self , ** kwargs ) -> None :
225228 super ().__init__ (** kwargs )
226229
227- def from_str (self , value ):
230+ def from_str (self , value : str ):
228231 raise NotImplementedError
229232
230233 def validate (self , value ):
0 commit comments