Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping returns PyList for keys, values, and items #4661

Merged
merged 20 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/4661.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`PyMapping`'s `keys`, `values` and `items` methods return `PyList` instead of `PySequence`.
20 changes: 10 additions & 10 deletions src/types/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::py_result_ext::PyResultExt;
use crate::sync::GILOnceCell;
use crate::type_object::PyTypeInfo;
use crate::types::any::PyAnyMethods;
use crate::types::{PyAny, PyDict, PySequence, PyType};
use crate::types::{PyAny, PyDict, PyList, PyType};
use crate::{ffi, Py, PyTypeCheck, Python};

/// Represents a reference to a Python object supporting the mapping protocol.
Expand Down Expand Up @@ -77,14 +77,14 @@ pub trait PyMappingMethods<'py>: crate::sealed::Sealed {
where
K: IntoPyObject<'py>;

/// Returns a sequence containing all keys in the mapping.
fn keys(&self) -> PyResult<Bound<'py, PySequence>>;
/// Returns a list containing all keys in the mapping.
fn keys(&self) -> PyResult<Bound<'py, PyList>>;

/// Returns a sequence containing all values in the mapping.
fn values(&self) -> PyResult<Bound<'py, PySequence>>;
/// Returns a list containing all values in the mapping.
fn values(&self) -> PyResult<Bound<'py, PyList>>;

/// Returns a sequence of tuples of all (key, value) pairs in the mapping.
fn items(&self) -> PyResult<Bound<'py, PySequence>>;
/// Returns a list of all (key, value) pairs in the mapping.
fn items(&self) -> PyResult<Bound<'py, PyList>>;
}

impl<'py> PyMappingMethods<'py> for Bound<'py, PyMapping> {
Expand Down Expand Up @@ -133,7 +133,7 @@ impl<'py> PyMappingMethods<'py> for Bound<'py, PyMapping> {
}

#[inline]
fn keys(&self) -> PyResult<Bound<'py, PySequence>> {
fn keys(&self) -> PyResult<Bound<'py, PyList>> {
unsafe {
ffi::PyMapping_Keys(self.as_ptr())
.assume_owned_or_err(self.py())
Expand All @@ -142,7 +142,7 @@ impl<'py> PyMappingMethods<'py> for Bound<'py, PyMapping> {
}

#[inline]
fn values(&self) -> PyResult<Bound<'py, PySequence>> {
fn values(&self) -> PyResult<Bound<'py, PyList>> {
unsafe {
ffi::PyMapping_Values(self.as_ptr())
.assume_owned_or_err(self.py())
Expand All @@ -151,7 +151,7 @@ impl<'py> PyMappingMethods<'py> for Bound<'py, PyMapping> {
}

#[inline]
fn items(&self) -> PyResult<Bound<'py, PySequence>> {
fn items(&self) -> PyResult<Bound<'py, PyList>> {
unsafe {
ffi::PyMapping_Items(self.as_ptr())
.assume_owned_or_err(self.py())
Expand Down
Loading