@@ -21,48 +21,49 @@ impl Constant {
2121 }
2222 }
2323
24- pub ( super ) fn new_int ( value : ruff:: Int , range : TextRange ) -> Self {
24+ pub ( super ) const fn new_int ( value : ruff:: Int , range : TextRange ) -> Self {
2525 Self {
2626 range,
2727 value : ConstantLiteral :: Int ( value) ,
2828 }
2929 }
3030
31- pub ( super ) fn new_float ( value : f64 , range : TextRange ) -> Self {
31+ pub ( super ) const fn new_float ( value : f64 , range : TextRange ) -> Self {
3232 Self {
3333 range,
3434 value : ConstantLiteral :: Float ( value) ,
3535 }
3636 }
37- pub ( super ) fn new_complex ( real : f64 , imag : f64 , range : TextRange ) -> Self {
37+
38+ pub ( super ) const fn new_complex ( real : f64 , imag : f64 , range : TextRange ) -> Self {
3839 Self {
3940 range,
4041 value : ConstantLiteral :: Complex { real, imag } ,
4142 }
4243 }
4344
44- pub ( super ) fn new_bytes ( value : Box < [ u8 ] > , range : TextRange ) -> Self {
45+ pub ( super ) const fn new_bytes ( value : Box < [ u8 ] > , range : TextRange ) -> Self {
4546 Self {
4647 range,
4748 value : ConstantLiteral :: Bytes ( value) ,
4849 }
4950 }
5051
51- pub ( super ) fn new_bool ( value : bool , range : TextRange ) -> Self {
52+ pub ( super ) const fn new_bool ( value : bool , range : TextRange ) -> Self {
5253 Self {
5354 range,
5455 value : ConstantLiteral :: Bool ( value) ,
5556 }
5657 }
5758
58- pub ( super ) fn new_none ( range : TextRange ) -> Self {
59+ pub ( super ) const fn new_none ( range : TextRange ) -> Self {
5960 Self {
6061 range,
6162 value : ConstantLiteral :: None ,
6263 }
6364 }
6465
65- pub ( super ) fn new_ellipsis ( range : TextRange ) -> Self {
66+ pub ( super ) const fn new_ellipsis ( range : TextRange ) -> Self {
6667 Self {
6768 range,
6869 value : ConstantLiteral :: Ellipsis ,
@@ -137,30 +138,30 @@ impl Node for Constant {
137138impl Node for ConstantLiteral {
138139 fn ast_to_object ( self , vm : & VirtualMachine , source_code : & SourceCodeOwned ) -> PyObjectRef {
139140 match self {
140- ConstantLiteral :: None => vm. ctx . none ( ) ,
141- ConstantLiteral :: Bool ( value) => vm. ctx . new_bool ( value) . to_pyobject ( vm) ,
142- ConstantLiteral :: Str { value, .. } => vm. ctx . new_str ( value) . to_pyobject ( vm) ,
143- ConstantLiteral :: Bytes ( value) => vm. ctx . new_bytes ( value. into ( ) ) . to_pyobject ( vm) ,
144- ConstantLiteral :: Int ( value) => value. ast_to_object ( vm, source_code) ,
145- ConstantLiteral :: Tuple ( value) => {
141+ Self :: None => vm. ctx . none ( ) ,
142+ Self :: Bool ( value) => vm. ctx . new_bool ( value) . to_pyobject ( vm) ,
143+ Self :: Str { value, .. } => vm. ctx . new_str ( value) . to_pyobject ( vm) ,
144+ Self :: Bytes ( value) => vm. ctx . new_bytes ( value. into ( ) ) . to_pyobject ( vm) ,
145+ Self :: Int ( value) => value. ast_to_object ( vm, source_code) ,
146+ Self :: Tuple ( value) => {
146147 let value = value
147148 . into_iter ( )
148149 . map ( |c| c. ast_to_object ( vm, source_code) )
149150 . collect ( ) ;
150151 vm. ctx . new_tuple ( value) . to_pyobject ( vm)
151152 }
152- ConstantLiteral :: FrozenSet ( value) => PyFrozenSet :: from_iter (
153+ Self :: FrozenSet ( value) => PyFrozenSet :: from_iter (
153154 vm,
154155 value. into_iter ( ) . map ( |c| c. ast_to_object ( vm, source_code) ) ,
155156 )
156157 . unwrap ( )
157158 . into_pyobject ( vm) ,
158- ConstantLiteral :: Float ( value) => vm. ctx . new_float ( value) . into_pyobject ( vm) ,
159- ConstantLiteral :: Complex { real, imag } => vm
159+ Self :: Float ( value) => vm. ctx . new_float ( value) . into_pyobject ( vm) ,
160+ Self :: Complex { real, imag } => vm
160161 . ctx
161162 . new_complex ( num_complex:: Complex :: new ( real, imag) )
162163 . into_pyobject ( vm) ,
163- ConstantLiteral :: Ellipsis => vm. ctx . ellipsis ( ) ,
164+ Self :: Ellipsis => vm. ctx . ellipsis ( ) ,
164165 }
165166 }
166167
@@ -171,24 +172,24 @@ impl Node for ConstantLiteral {
171172 ) -> PyResult < Self > {
172173 let cls = value_object. class ( ) ;
173174 let value = if cls. is ( vm. ctx . types . none_type ) {
174- ConstantLiteral :: None
175+ Self :: None
175176 } else if cls. is ( vm. ctx . types . bool_type ) {
176- ConstantLiteral :: Bool ( if value_object. is ( & vm. ctx . true_value ) {
177+ Self :: Bool ( if value_object. is ( & vm. ctx . true_value ) {
177178 true
178179 } else if value_object. is ( & vm. ctx . false_value ) {
179180 false
180181 } else {
181182 value_object. try_to_value ( vm) ?
182183 } )
183184 } else if cls. is ( vm. ctx . types . str_type ) {
184- ConstantLiteral :: Str {
185+ Self :: Str {
185186 value : value_object. try_to_value :: < String > ( vm) ?. into ( ) ,
186187 prefix : StringLiteralPrefix :: Empty ,
187188 }
188189 } else if cls. is ( vm. ctx . types . bytes_type ) {
189- ConstantLiteral :: Bytes ( value_object. try_to_value :: < Vec < u8 > > ( vm) ?. into ( ) )
190+ Self :: Bytes ( value_object. try_to_value :: < Vec < u8 > > ( vm) ?. into ( ) )
190191 } else if cls. is ( vm. ctx . types . int_type ) {
191- ConstantLiteral :: Int ( Node :: ast_from_object ( vm, source_code, value_object) ?)
192+ Self :: Int ( Node :: ast_from_object ( vm, source_code, value_object) ?)
192193 } else if cls. is ( vm. ctx . types . tuple_type ) {
193194 let tuple = value_object. downcast :: < PyTuple > ( ) . map_err ( |obj| {
194195 vm. new_type_error ( format ! (
@@ -202,18 +203,18 @@ impl Node for ConstantLiteral {
202203 . cloned ( )
203204 . map ( |object| Node :: ast_from_object ( vm, source_code, object) )
204205 . collect :: < PyResult < _ > > ( ) ?;
205- ConstantLiteral :: Tuple ( tuple)
206+ Self :: Tuple ( tuple)
206207 } else if cls. is ( vm. ctx . types . frozenset_type ) {
207208 let set = value_object. downcast :: < PyFrozenSet > ( ) . unwrap ( ) ;
208209 let elements = set
209210 . elements ( )
210211 . into_iter ( )
211212 . map ( |object| Node :: ast_from_object ( vm, source_code, object) )
212213 . collect :: < PyResult < _ > > ( ) ?;
213- ConstantLiteral :: FrozenSet ( elements)
214+ Self :: FrozenSet ( elements)
214215 } else if cls. is ( vm. ctx . types . float_type ) {
215216 let float = value_object. try_into_value ( vm) ?;
216- ConstantLiteral :: Float ( float)
217+ Self :: Float ( float)
217218 } else if cls. is ( vm. ctx . types . complex_type ) {
218219 let complex = value_object. try_complex ( vm) ?;
219220 let complex = match complex {
@@ -226,12 +227,12 @@ impl Node for ConstantLiteral {
226227 }
227228 Some ( ( value, _was_coerced) ) => value,
228229 } ;
229- ConstantLiteral :: Complex {
230+ Self :: Complex {
230231 real : complex. re ,
231232 imag : complex. im ,
232233 }
233234 } else if cls. is ( vm. ctx . types . ellipsis_type ) {
234- ConstantLiteral :: Ellipsis
235+ Self :: Ellipsis
235236 } else {
236237 return Err ( vm. new_type_error ( format ! (
237238 "invalid type in Constant: {}" ,
0 commit comments