File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -364,6 +364,7 @@ impl PyStr {
364364#[ pyclass(
365365 flags( BASETYPE ) ,
366366 with(
367+ PyRef ,
367368 AsMapping ,
368369 AsNumber ,
369370 AsSequence ,
@@ -481,11 +482,6 @@ impl PyStr {
481482 Self :: repeat ( zelf, value. into ( ) , vm)
482483 }
483484
484- #[ pymethod( magic) ]
485- fn str ( zelf : PyRef < Self > ) -> PyStrRef {
486- zelf
487- }
488-
489485 #[ inline]
490486 pub ( crate ) fn repr ( & self , vm : & VirtualMachine ) -> PyResult < String > {
491487 rustpython_common:: str:: repr ( self . as_str ( ) )
@@ -1270,6 +1266,17 @@ impl PyStr {
12701266 }
12711267}
12721268
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+
12731280impl PyStrRef {
12741281 pub fn concat_in_place ( & mut self , other : & str , vm : & VirtualMachine ) {
12751282 // 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