瀏覽代碼

Avoid PyObject, deprecated in PyO3 0.26 (#1917)

Jelmer Vernooij 3 月之前
父節點
當前提交
820758ac31
共有 3 個文件被更改,包括 15 次插入15 次删除
  1. 6 6
      crates/diff-tree/src/lib.rs
  2. 5 5
      crates/objects/src/lib.rs
  3. 4 4
      crates/pack/src/lib.rs

+ 6 - 6
crates/diff-tree/src/lib.rs

@@ -40,7 +40,7 @@ fn add_hash(get: &Bound<PyAny>, set: &Bound<PyAny>, string: &[u8], py: Python) -
 }
 
 #[pyfunction]
-fn _count_blocks(py: Python, obj: &Bound<PyAny>) -> PyResult<PyObject> {
+fn _count_blocks(py: Python, obj: &Bound<PyAny>) -> PyResult<Py<PyAny>> {
     let default_dict_cls = PyModule::import(py, "collections")?.getattr("defaultdict")?;
     let int_cls = PyModule::import(py, "builtins")?.getattr("int")?;
 
@@ -55,7 +55,7 @@ fn _count_blocks(py: Python, obj: &Bound<PyAny>) -> PyResult<PyObject> {
         ));
     }
 
-    let num_chunks = chunks.extract::<Vec<PyObject>>()?.len();
+    let num_chunks = chunks.extract::<Vec<Py<PyAny>>>()?.len();
     let pym = py.import("dulwich.diff_tree")?;
     let block_size = pym.getattr("_BLOCK_SIZE")?.extract::<usize>()?;
     let mut block: Vec<u8> = Vec::with_capacity(block_size);
@@ -98,7 +98,7 @@ fn _is_tree(_py: Python, entry: &Bound<PyAny>) -> PyResult<bool> {
     }
 }
 
-fn tree_entries(path: &[u8], tree: &Bound<PyAny>, py: Python) -> PyResult<Vec<PyObject>> {
+fn tree_entries(path: &[u8], tree: &Bound<PyAny>, py: Python) -> PyResult<Vec<Py<PyAny>>> {
     if tree.is_none() {
         return Ok(Vec::new());
     }
@@ -108,11 +108,11 @@ fn tree_entries(path: &[u8], tree: &Bound<PyAny>, py: Python) -> PyResult<Vec<Py
 
     let items = tree
         .call_method1("iteritems", (true,))?
-        .extract::<Vec<PyObject>>()?;
+        .extract::<Vec<Py<PyAny>>>()?;
 
     let mut result = Vec::new();
     for item in items {
-        let (name, mode, sha) = item.extract::<(Vec<u8>, u32, PyObject)>(py)?;
+        let (name, mode, sha) = item.extract::<(Vec<u8>, u32, Py<PyAny>)>(py)?;
 
         let mut new_path = Vec::with_capacity(path.len() + name.len() + 1);
         if !path.is_empty() {
@@ -142,7 +142,7 @@ fn _merge_entries(
     path: &[u8],
     tree1: &Bound<PyAny>,
     tree2: &Bound<PyAny>,
-) -> PyResult<PyObject> {
+) -> PyResult<Py<PyAny>> {
     let entries1 = tree_entries(path, tree1, py)?;
     let entries2 = tree_entries(path, tree2, py)?;
 

+ 5 - 5
crates/objects/src/lib.rs

@@ -39,7 +39,7 @@ fn bytehex(byte: u8) -> u8 {
     }
 }
 
-fn sha_to_pyhex(py: Python, sha: &[u8]) -> PyResult<PyObject> {
+fn sha_to_pyhex(py: Python, sha: &[u8]) -> PyResult<Py<PyAny>> {
     let mut hexsha = Vec::new();
     for c in sha {
         hexsha.push(bytehex((c & 0xF0) >> 4));
@@ -55,7 +55,7 @@ fn parse_tree(
     py: Python,
     mut text: &[u8],
     strict: Option<bool>,
-) -> PyResult<Vec<(PyObject, u32, PyObject)>> {
+) -> PyResult<Vec<(Py<PyAny>, u32, Py<PyAny>)>> {
     let mut entries = Vec::new();
     let strict = strict.unwrap_or(false);
     while !text.is_empty() {
@@ -119,7 +119,7 @@ fn sorted_tree_items(
     py: Python,
     entries: &Bound<PyDict>,
     name_order: bool,
-) -> PyResult<Vec<PyObject>> {
+) -> PyResult<Vec<Py<PyAny>>> {
     let mut qsort_entries = entries
         .iter()
         .map(|(name, value)| -> PyResult<(Vec<u8>, u32, Vec<u8>)> {
@@ -138,7 +138,7 @@ fn sorted_tree_items(
     let tree_entry_cls = objectsm.getattr("TreeEntry")?;
     qsort_entries
         .into_iter()
-        .map(|(name, mode, hexsha)| -> PyResult<PyObject> {
+        .map(|(name, mode, hexsha)| -> PyResult<Py<PyAny>> {
             Ok(tree_entry_cls
                 .call1((
                     PyBytes::new(py, name.as_slice())
@@ -154,7 +154,7 @@ fn sorted_tree_items(
                 .unbind()
                 .into())
         })
-        .collect::<PyResult<Vec<PyObject>>>()
+        .collect::<PyResult<Vec<Py<PyAny>>>>()
 }
 
 #[pymodule]

+ 4 - 4
crates/pack/src/lib.rs

@@ -24,7 +24,7 @@ use pyo3::types::{PyBytes, PyList};
 
 pyo3::import_exception!(dulwich.errors, ApplyDeltaError);
 
-fn py_is_sha(sha: &PyObject, py: Python) -> PyResult<bool> {
+fn py_is_sha(sha: &Py<PyAny>, py: Python) -> PyResult<bool> {
     // Check if the object is a bytes object
     if sha.bind(py).is_instance_of::<PyBytes>() {
         // Check if the bytes object has a size of 20
@@ -44,7 +44,7 @@ fn bisect_find_sha(
     start: i32,
     end: i32,
     sha: Py<PyBytes>,
-    unpack_name: PyObject,
+    unpack_name: Py<PyAny>,
 ) -> PyResult<Option<i32>> {
     // Convert sha_obj to a byte slice
     let sha = sha.as_bytes(py);
@@ -107,7 +107,7 @@ fn get_delta_header_size(delta: &[u8], index: &mut usize, length: usize) -> usiz
 
 fn py_chunked_as_string<'a>(
     py: Python<'a>,
-    py_buf: &'a PyObject,
+    py_buf: &'a Py<PyAny>,
 ) -> PyResult<std::borrow::Cow<'a, [u8]>> {
     if let Ok(py_list) = py_buf.extract::<Bound<PyList>>(py) {
         let mut buf = Vec::new();
@@ -134,7 +134,7 @@ fn py_chunked_as_string<'a>(
 }
 
 #[pyfunction]
-fn apply_delta(py: Python, py_src_buf: PyObject, py_delta: PyObject) -> PyResult<Vec<PyObject>> {
+fn apply_delta(py: Python, py_src_buf: Py<PyAny>, py_delta: Py<PyAny>) -> PyResult<Vec<Py<PyAny>>> {
     let src_buf = py_chunked_as_string(py, &py_src_buf)?;
     let delta = py_chunked_as_string(py, &py_delta)?;