rust-python3: compatibility fix for integer conversion
authorGeorges Racinet <georges.racinet@octobus.net>
Thu, 16 May 2019 21:17:14 +0200
changeset 42354 163b8fd7bb72
parent 42353 d6c1dd936778
child 42355 da3861ef7959
rust-python3: compatibility fix for integer conversion 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. Differential Revision: https://phab.mercurial-scm.org/D6396
rust/hg-cpython/src/discovery.rs
--- a/rust/hg-cpython/src/discovery.rs	Fri May 17 09:42:02 2019 -0400
+++ b/rust/hg-cpython/src/discovery.rs	Thu May 16 21:17:14 2019 +0200
@@ -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)
     }