File tree 3 files changed +17
-1
lines changed
3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,9 @@ fn _obstore(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
55
55
pyo3_object_store:: register_exceptions_module ( py, m, "obstore" ) ?;
56
56
57
57
m. add_class :: < pyo3_bytes:: PyBytes > ( ) ?;
58
+ // Set the value of `__module__` correctly on PyBytes
59
+ m. getattr ( "Bytes" ) ?. setattr ( "__module__" , "obstore" ) ?;
60
+
58
61
m. add_wrapped ( wrap_pyfunction ! ( buffered:: open_reader) ) ?;
59
62
m. add_wrapped ( wrap_pyfunction ! ( buffered:: open_reader_async) ) ?;
60
63
m. add_wrapped ( wrap_pyfunction ! ( buffered:: open_writer) ) ?;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ use bytes::{Bytes, BytesMut};
8
8
use pyo3:: buffer:: PyBuffer ;
9
9
use pyo3:: exceptions:: { PyIndexError , PyValueError } ;
10
10
use pyo3:: prelude:: * ;
11
- use pyo3:: types:: PySlice ;
11
+ use pyo3:: types:: { PyDict , PySlice , PyTuple } ;
12
12
use pyo3:: { ffi, IntoPyObjectExt } ;
13
13
14
14
/// A wrapper around a [`bytes::Bytes`][].
@@ -161,6 +161,13 @@ impl PyBytes {
161
161
buf
162
162
}
163
163
164
+ fn __getnewargs_ex__ ( & self , py : Python ) -> PyResult < PyObject > {
165
+ let py_bytes = self . to_bytes ( py) ;
166
+ let args = PyTuple :: new ( py, vec ! [ py_bytes] ) ?. into_py_any ( py) ?;
167
+ let kwargs = PyDict :: new ( py) ;
168
+ PyTuple :: new ( py, [ args, kwargs. into_py_any ( py) ?] ) ?. into_py_any ( py)
169
+ }
170
+
164
171
/// The number of bytes in this Bytes
165
172
fn __len__ ( & self ) -> usize {
166
173
self . 0 . len ( )
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
+ import pickle
3
4
from typing import TYPE_CHECKING
4
5
5
6
import pytest
@@ -93,3 +94,8 @@ def _bytes_slices(
93
94
for stop in indices_range
94
95
for step in steps
95
96
)
97
+
98
+
99
+ def test_pickle ():
100
+ b = Bytes (b"hello_world" )
101
+ assert b == pickle .loads (pickle .dumps (b ))
You can’t perform that action at this time.
0 commit comments