File tree 1 file changed +12
-5
lines changed
1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -364,6 +364,7 @@ impl PyStr {
364
364
#[ pyclass(
365
365
flags( BASETYPE ) ,
366
366
with(
367
+ PyRef ,
367
368
AsMapping ,
368
369
AsNumber ,
369
370
AsSequence ,
@@ -481,11 +482,6 @@ impl PyStr {
481
482
Self :: repeat ( zelf, value. into ( ) , vm)
482
483
}
483
484
484
- #[ pymethod( magic) ]
485
- fn str ( zelf : PyRef < Self > ) -> PyStrRef {
486
- zelf
487
- }
488
-
489
485
#[ inline]
490
486
pub ( crate ) fn repr ( & self , vm : & VirtualMachine ) -> PyResult < String > {
491
487
rustpython_common:: str:: repr ( self . as_str ( ) )
@@ -1270,6 +1266,17 @@ impl PyStr {
1270
1266
}
1271
1267
}
1272
1268
1269
+ #[ pyclass]
1270
+ impl PyRef < PyStr > {
1271
+ #[ pymethod( magic) ]
1272
+ fn str ( self , vm : & VirtualMachine ) -> PyRefExact < PyStr > {
1273
+ self . into_exact_or ( & vm. ctx , |zelf| unsafe {
1274
+ // Creating a copy with same kind is safe
1275
+ PyStr :: new_str_unchecked ( zelf. bytes . to_vec ( ) , zelf. kind . kind ( ) ) . into_exact_ref ( & vm. ctx )
1276
+ } )
1277
+ }
1278
+ }
1279
+
1273
1280
impl PyStrRef {
1274
1281
pub fn concat_in_place ( & mut self , other : & str , vm : & VirtualMachine ) {
1275
1282
// TODO: call [A]Rc::get_mut on the str to try to mutate the data in place
You can’t perform that action at this time.
0 commit comments