Implement bytes.__bytes__
This commit implement `bytes.__bytes__` in cpython 3.11 for typing
module.
*
*
@@ -128,6 +128,15 @@ impl PyBytes {
&self.inner.elements
}
+ #[pymethod(magic)]
+ fn bytes(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyRef<Self> {
+ if zelf.is(&vm.ctx.types.bytes_type) {
+ zelf
+ } else {
+ PyBytes::from(zelf.inner.clone()).into_ref(vm)
+ }
+ }
+
#[pymethod(magic)]
fn sizeof(&self) -> usize {
size_of::<Self>() + self.inner.elements.len() * size_of::<u8>()
