Skip to content

Commit

Permalink
Clippy and cargo check
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhly committed Oct 16, 2023
1 parent 38671ad commit 85b554f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
7 changes: 6 additions & 1 deletion pyo3-ffi/src/descrobject.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::methodobject::PyMethodDef;
use crate::object::{PyObject, PyTypeObject};
use crate::Py_ssize_t;
use crate::{PyObject_TypeCheck, Py_ssize_t};
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;

Expand Down Expand Up @@ -68,6 +68,11 @@ extern "C" {
pub fn PyWrapper_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject;
}

#[inline]
pub unsafe fn PyDictProxy_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, std::ptr::addr_of_mut!(PyDictProxy_Type))
}

/// Represents the [PyMemberDef](https://docs.python.org/3/c-api/structures.html#c.PyMemberDef)
/// structure.
///
Expand Down
29 changes: 11 additions & 18 deletions src/types/mappingproxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@
use super::PyMapping;
use crate::err::PyResult;
use crate::types::dict::{IntoPyDict, PyDictItem};
#[cfg(all(test, not(PyPy)))]
use crate::types::dict::{PyDictItems, PyDictKeys, PyDictValues};
use crate::types::{PyAny, PyIterator, PyList, PySequence};
#[cfg(not(PyPy))]
use crate::{ffi, AsPyPointer, PyErr, PyTryFrom, Python, ToPyObject};
use std::os::raw::c_int;

#[allow(non_snake_case)]
unsafe fn PyDictProxy_Check(object: *mut crate::ffi::PyObject) -> c_int {
ffi::PyObject_TypeCheck(object, std::ptr::addr_of_mut!(ffi::PyDictProxy_Type))
}

/// Represents a Python `mappingproxy`.
#[repr(transparent)]
pub struct PyMappingProxy(PyAny);

#[cfg(not(PyPy))]
pyobject_native_type_core!(
PyMappingProxy,
pyobject_native_static_type_object!(ffi::PyDictProxy_Type),
#checkfunction=PyDictProxy_Check
#checkfunction=ffi::PyDictProxy_Check
);

impl PyMappingProxy {
Expand Down Expand Up @@ -155,12 +147,13 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::type_object::PyTypeInfo;
#[cfg(not(PyPy))]
use crate::Python;
use crate::{
exceptions::PyKeyError,
types::{PyInt, PyString, PyTuple},
types::{PyDictItems, PyDictKeys, PyDictValues, PyInt, PyString, PyTuple},
};
#[cfg(not(PyPy))]
use crate::{PyTypeInfo, Python};
use std::collections::{BTreeMap, HashMap};

#[test]
Expand Down Expand Up @@ -268,7 +261,7 @@ mod tests {
// Can't just compare against a vector of tuples since we don't have a guaranteed ordering.
let mut key_sum = 0;
let mut value_sum = 0;
for el in mappingproxy.items().iter() {
for el in mappingproxy.items() {
let tuple = el.downcast::<PyTuple>().unwrap();
key_sum += tuple.get_item(0).unwrap().extract::<i32>().unwrap();
value_sum += tuple.get_item(1).unwrap().extract::<i32>().unwrap();
Expand Down Expand Up @@ -297,7 +290,7 @@ mod tests {
let mappingproxy = v.into_py_mappingproxy(py).unwrap();
// Can't just compare against a vector of tuples since we don't have a guaranteed ordering.
let mut key_sum = 0;
for el in mappingproxy.keys().iter() {
for el in mappingproxy.keys() {
key_sum += el.extract::<i32>().unwrap();
}
assert_eq!(7 + 8 + 9, key_sum);
Expand All @@ -314,7 +307,7 @@ mod tests {
let mappingproxy = v.into_py_mappingproxy(py).unwrap();
// Can't just compare against a vector of tuples since we don't have a guaranteed ordering.
let mut values_sum = 0;
for el in mappingproxy.values().iter() {
for el in mappingproxy.values() {
values_sum += el.extract::<i32>().unwrap();
}
assert_eq!(32 + 42 + 123, values_sum);
Expand All @@ -331,7 +324,7 @@ mod tests {
let mappingproxy = v.into_py_mappingproxy(py).unwrap();
let mut key_sum = 0;
let mut value_sum = 0;
for (key, value) in mappingproxy.iter() {
for (key, value) in mappingproxy {
key_sum += key.extract::<i32>().unwrap();
value_sum += value.extract::<i32>().unwrap();
}
Expand Down Expand Up @@ -593,7 +586,7 @@ mod tests {
.unwrap();

let mut sum = 0;
for (k, _v) in mappingproxy.iter() {
for (k, _v) in mappingproxy {
let i: u64 = k.extract().unwrap();
sum += i;
}
Expand Down

0 comments on commit 85b554f

Please sign in to comment.