D6396: rust-python3: compatibility fix for integer conversion

gracinet (Georges Racinet) phabricator at mercurial-scm.org
Fri May 17 07:42:45 EDT 2019


gracinet created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  On python3, `to_py_object()` on the usize gives us a PyLong,
  whereas it is the generic `PyObject` already on python2, which fits
  the `py.None()` default value.
  
  Upcasting to `PyObject` explicitely in all cases solves the issue.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6396

AFFECTED FILES
  rust/hg-cpython/src/discovery.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/discovery.rs b/rust/hg-cpython/src/discovery.rs
--- a/rust/hg-cpython/src/discovery.rs
+++ b/rust/hg-cpython/src/discovery.rs
@@ -15,7 +15,8 @@
 use crate::conversion::{py_set, rev_pyiter_collect};
 use cindex::Index;
 use cpython::{
-    ObjectProtocol, PyDict, PyModule, PyObject, PyResult, Python, ToPyObject,
+    ObjectProtocol, PyDict, PyModule, PyObject, PyResult, Python,
+    PythonObject, ToPyObject,
 };
 use exceptions::GraphError;
 use hg::discovery::PartialDiscovery as CorePartialDiscovery;
@@ -89,8 +90,9 @@
         let stats = self.inner(py).borrow().stats();
         let as_dict: PyDict = PyDict::new(py);
         as_dict.set_item(py, "undecided",
-                         stats.undecided.map(|l| l.to_py_object(py))
-                              .unwrap_or_else(|| py.None()))?;
+                         stats.undecided.map(
+                             |l| l.to_py_object(py).into_object())
+                             .unwrap_or_else(|| py.None()))?;
         Ok(as_dict)
     }
 



To: gracinet, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel


More information about the Mercurial-devel mailing list