11//! Implementation of the python bytearray object.
22use super :: {
3- PositionIterInternal , PyBytes , PyBytesRef , PyDictRef , PyIntRef , PyStrRef , PyTuple , PyTupleRef ,
4- PyType , PyTypeRef ,
3+ PositionIterInternal , PyBytes , PyBytesRef , PyDictRef , PyIntRef , PyStr , PyStrRef , PyTuple ,
4+ PyTupleRef , PyType , PyTypeRef ,
55} ;
66use crate :: {
77 anystr:: { self , AnyStr } ,
@@ -31,7 +31,7 @@ use crate::{
3131 sliceable:: { SequenceIndex , SliceableSequenceMutOp , SliceableSequenceOp } ,
3232 types:: {
3333 AsBuffer , AsMapping , AsNumber , AsSequence , Callable , Comparable , Constructor , Initializer ,
34- IterNext , IterNextIterable , Iterable , PyComparisonOp , Unconstructible ,
34+ IterNext , IterNextIterable , Iterable , PyComparisonOp , Representable , Unconstructible ,
3535 } ,
3636 AsObject , Context , Py , PyObject , PyObjectRef , PyPayload , PyRef , PyResult , TryFromObject ,
3737 VirtualMachine ,
@@ -107,7 +107,8 @@ pub(crate) fn init(context: &Context) {
107107 AsMapping ,
108108 AsSequence ,
109109 AsNumber ,
110- Iterable
110+ Iterable ,
111+ Representable
111112 )
112113) ]
113114impl PyByteArray {
@@ -126,13 +127,6 @@ impl PyByteArray {
126127 self . inner . write ( )
127128 }
128129
129- #[ pymethod( magic) ]
130- fn repr ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < String > {
131- let class = zelf. class ( ) ;
132- let class_name = class. name ( ) ;
133- zelf. inner ( ) . repr ( Some ( & class_name) , vm)
134- }
135-
136130 #[ pymethod( magic) ]
137131 fn alloc ( & self ) -> usize {
138132 self . inner ( ) . capacity ( )
@@ -886,6 +880,17 @@ impl Iterable for PyByteArray {
886880 }
887881}
888882
883+ impl Representable for PyByteArray {
884+ #[ inline]
885+ fn repr ( zelf : & crate :: Py < Self > , vm : & VirtualMachine ) -> PyResult < PyStrRef > {
886+ let class = zelf. class ( ) ;
887+ let class_name = class. name ( ) ;
888+ zelf. inner ( )
889+ . repr ( Some ( & class_name) , vm)
890+ . map ( |s| PyStr :: from ( s) . into_ref ( vm) )
891+ }
892+ }
893+
889894// fn set_value(obj: &PyObject, value: Vec<u8>) {
890895// obj.borrow_mut().kind = PyObjectPayload::Bytes { value };
891896// }
@@ -922,6 +927,7 @@ impl PyByteArrayIterator {
922927 . set_state ( state, |obj, pos| pos. min ( obj. len ( ) ) , vm)
923928 }
924929}
930+
925931impl Unconstructible for PyByteArrayIterator { }
926932
927933impl IterNextIterable for PyByteArrayIterator { }
0 commit comments