From 482ee3a8b202b824e3f8b85fa31e11cca94d42fa Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Mon, 12 Oct 2020 14:35:27 +0100 Subject: [PATCH] Add changelog entry and test --- CHANGELOG.md | 3 +++ src/types/iterator.rs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60918324..7b4774cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Change `PyIterator` to be consistent with other native types: it is now used as `&PyIterator` instead of `PyIterator<'a>`. [#1176](https://github.com/PyO3/pyo3/pull/1176) + ### Removed - Remove unused `python3` feature. [#1209](https://github.com/PyO3/pyo3/pull/1209) diff --git a/src/types/iterator.rs b/src/types/iterator.rs index 59506012..4666d39e 100644 --- a/src/types/iterator.rs +++ b/src/types/iterator.rs @@ -96,8 +96,7 @@ mod tests { use crate::exceptions::PyTypeError; use crate::gil::GILPool; use crate::types::{PyDict, PyList}; - use crate::Python; - use crate::ToPyObject; + use crate::{Python, Py, PyAny, ToPyObject, PyTryFrom}; use indoc::indoc; #[test] @@ -199,4 +198,13 @@ mod tests { assert!(err.is_instance::(py)) } + + #[test] + fn iterator_try_from() { + let gil_guard = Python::acquire_gil(); + let py = gil_guard.python(); + let obj: Py = vec![10, 20].to_object(py).as_ref(py).iter().unwrap().into(); + let iter: &PyIterator = PyIterator::try_from(obj.as_ref(py)).unwrap(); + assert_eq!(obj, iter.into()); + } }