Mercurial > hg
changeset 42332:163b8fd7bb72
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
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Thu, 16 May 2019 21:17:14 +0200 |
parents | d6c1dd936778 |
children | da3861ef7959 |
files | rust/hg-cpython/src/discovery.rs |
diffstat | 1 files changed, 5 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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) }