# HG changeset patch # User Georges Racinet # Date 1558034234 -7200 # Node ID 163b8fd7bb7247142b3c9706dcfac346bf598a3a # Parent d6c1dd9367784b279e500e42b7ae8b0eb78915a6 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 diff -r d6c1dd936778 -r 163b8fd7bb72 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) }