Skip to content

Commit 9d75325

Browse files
authored
Merge pull request #3532 from davidhewitt/dict-from-seq
change `PyDict::from_sequence` to take just `&PyAny`
2 parents d8a6f37 + d895734 commit 9d75325

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

newsfragments/3532.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- `PyDict::from_sequence` now takes a single argument of type `&PyAny` (previously took two arguments `Python` and `PyObject`).

src/types/dict.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ impl PyDict {
6565
/// Returns an error on invalid input. In the case of key collisions,
6666
/// this keeps the last entry seen.
6767
#[cfg(not(PyPy))]
68-
pub fn from_sequence(py: Python<'_>, seq: PyObject) -> PyResult<&PyDict> {
68+
pub fn from_sequence(seq: &PyAny) -> PyResult<&PyDict> {
69+
let py = seq.py();
6970
let dict = Self::new(py);
7071
err::error_on_minusone(py, unsafe {
7172
ffi::PyDict_MergeFromSeq2(dict.into_ptr(), seq.into_ptr(), 1)
@@ -505,7 +506,7 @@ mod tests {
505506
fn test_from_sequence() {
506507
Python::with_gil(|py| {
507508
let items = PyList::new(py, &vec![("a", 1), ("b", 2)]);
508-
let dict = PyDict::from_sequence(py, items.to_object(py)).unwrap();
509+
let dict = PyDict::from_sequence(items).unwrap();
509510
assert_eq!(
510511
1,
511512
dict.get_item("a")
@@ -534,7 +535,7 @@ mod tests {
534535
fn test_from_sequence_err() {
535536
Python::with_gil(|py| {
536537
let items = PyList::new(py, &vec!["a", "b"]);
537-
assert!(PyDict::from_sequence(py, items.to_object(py)).is_err());
538+
assert!(PyDict::from_sequence(items).is_err());
538539
});
539540
}
540541

0 commit comments

Comments
 (0)