Fix some clippy warnings (#26)
This commit is contained in:
parent
8188c9533c
commit
cb68cd23a2
|
@ -281,7 +281,7 @@ macro_rules! py_func_set{
|
|||
py, format!("Subscript deletion not supported by {:?}",
|
||||
stringify!(T)));
|
||||
e.restore(py);
|
||||
return -1
|
||||
-1
|
||||
} else {
|
||||
let name = ::PyObject::from_borrowed_ptr(py, name);
|
||||
let value = ::PyObject::from_borrowed_ptr(py, value);
|
||||
|
@ -356,7 +356,7 @@ macro_rules! py_func_del{
|
|||
py, format!("Subscript assignment not supported by {:?}",
|
||||
stringify!(T)));
|
||||
e.restore(py);
|
||||
return -1
|
||||
-1
|
||||
|
||||
}
|
||||
})
|
||||
|
|
|
@ -200,7 +200,7 @@ impl<T> PySequenceSetItemProtocolImpl for T
|
|||
py,
|
||||
format!("Item deletion not supported by {:?}", stringify!(T)));
|
||||
e.restore(py);
|
||||
return -1
|
||||
-1
|
||||
} else {
|
||||
let value = PyObject::from_borrowed_ptr(py, value);
|
||||
let result = match value.extract(py) {
|
||||
|
@ -260,7 +260,7 @@ impl<T> PySequenceDelItemProtocolImpl for T
|
|||
py, format!("Item assignment not supported by {:?}",
|
||||
stringify!(T)));
|
||||
e.restore(py);
|
||||
return -1
|
||||
-1
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use objects::{PyObject, PyTuple};
|
|||
use typeob::PyTypeInfo;
|
||||
|
||||
|
||||
/// Conversion trait that allows various objects to be converted into PyObject
|
||||
/// Conversion trait that allows various objects to be converted into `PyObject`
|
||||
pub trait ToPyObject {
|
||||
|
||||
/// Converts self into a Python object.
|
||||
|
@ -36,7 +36,7 @@ pub trait IntoPyObject {
|
|||
}
|
||||
|
||||
|
||||
/// Conversion trait that allows various objects to be converted into PyTuple object.
|
||||
/// Conversion trait that allows various objects to be converted into `PyTuple` object.
|
||||
pub trait IntoPyTuple {
|
||||
|
||||
/// Converts self into a PyTuple object.
|
||||
|
@ -45,7 +45,7 @@ pub trait IntoPyTuple {
|
|||
}
|
||||
|
||||
|
||||
/// FromPyObject is implemented by various types that can be extracted from a Python object.
|
||||
/// `FromPyObject` is implemented by various types that can be extracted from a Python object.
|
||||
///
|
||||
/// Normal usage is through the `PyObject::extract` helper method:
|
||||
/// ```let obj: PyObject = ...;
|
||||
|
@ -101,7 +101,7 @@ impl <'p, T: ?Sized> RefFromPyObject<'p> for T
|
|||
|
||||
/// Identity conversion: allows using existing `PyObject` instances where
|
||||
/// `T: ToPyObject` is expected.
|
||||
// ToPyObject for references
|
||||
// `ToPyObject` for references
|
||||
impl <'a, T: ?Sized> ToPyObject for &'a T where T: ToPyObject {
|
||||
|
||||
#[inline]
|
||||
|
@ -150,7 +150,7 @@ impl IntoPyObject for () {
|
|||
}
|
||||
}
|
||||
|
||||
/// Extract reference to instance from PyObject
|
||||
/// Extract reference to instance from `PyObject`
|
||||
impl<'source, T> FromPyObject<'source> for &'source T
|
||||
where T: PyTypeInfo + PyDowncastFrom
|
||||
{
|
||||
|
|
|
@ -371,7 +371,7 @@ impl <'p> std::fmt::Debug for PyDowncastError<'p> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Convert PyErr to io::Error
|
||||
/// Convert `PyErr` to `io::Error`
|
||||
impl std::convert::From<PyErr> for std::io::Error {
|
||||
fn from(err: PyErr) -> Self {
|
||||
std::io::Error::new(
|
||||
|
@ -379,7 +379,7 @@ impl std::convert::From<PyErr> for std::io::Error {
|
|||
}
|
||||
}
|
||||
|
||||
/// Converts into PyErr
|
||||
/// Converts into `PyErr`
|
||||
pub trait ToPyErr {
|
||||
fn to_pyerr(&self, Python) -> PyErr;
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ macro_rules! impl_to_pyerr {
|
|||
}
|
||||
}
|
||||
|
||||
/// Create OSError from io::Error
|
||||
/// Create `OSError` from `io::Error`
|
||||
impl ToPyErr for io::Error {
|
||||
|
||||
fn to_pyerr(&self, py: Python) -> PyErr {
|
||||
|
|
|
@ -3,7 +3,7 @@ use ffi::pyport::Py_ssize_t;
|
|||
use ffi::object::*;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyCodeObject {
|
||||
pub ob_base: PyObject,
|
||||
pub co_argcount: c_int,
|
||||
|
@ -30,9 +30,7 @@ pub struct PyCodeObject {
|
|||
#[cfg(Py_3_6)]
|
||||
pub co_extra: *mut c_void,
|
||||
}
|
||||
impl Clone for PyCodeObject {
|
||||
#[inline] fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
impl Default for PyCodeObject {
|
||||
#[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } }
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ pub type setter =
|
|||
unsafe extern "C" fn(slf: *mut PyObject, value: *mut PyObject, closure: *mut c_void) -> c_int;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Debug)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct PyGetSetDef {
|
||||
pub name: *mut c_char,
|
||||
pub get: Option<getter>,
|
||||
|
@ -28,10 +28,6 @@ pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef {
|
|||
closure: ptr::null_mut(),
|
||||
};
|
||||
|
||||
impl Clone for PyGetSetDef {
|
||||
#[inline] fn clone(&self) -> PyGetSetDef { *self }
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
|
||||
pub static mut PyClassMethodDescr_Type: PyTypeObject;
|
||||
pub static mut PyGetSetDescr_Type: PyTypeObject;
|
||||
|
|
|
@ -39,7 +39,7 @@ pub type PyNoArgsFunction =
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyMethodDef {
|
||||
pub ml_name: *const c_char,
|
||||
pub ml_meth: Option<PyCFunction>,
|
||||
|
@ -54,9 +54,6 @@ pub const PyMethodDef_INIT : PyMethodDef = PyMethodDef {
|
|||
ml_doc: 0 as *const _,
|
||||
};
|
||||
|
||||
impl Clone for PyMethodDef {
|
||||
#[inline] fn clone(&self) -> PyMethodDef { *self }
|
||||
}
|
||||
impl Default for PyMethodDef {
|
||||
fn default() -> PyMethodDef { unsafe { mem::zeroed() } }
|
||||
}
|
||||
|
@ -86,7 +83,7 @@ pub const METH_STATIC : c_int = 0x0020;
|
|||
|
||||
/* METH_COEXIST allows a method to be entered eventhough a slot has
|
||||
already filled the entry. When defined, the flag allows a separate
|
||||
method, "__contains__" for example, to coexist with a defined
|
||||
method, "__contains__" for example, to coexist with a defined
|
||||
slot like sq_contains. */
|
||||
|
||||
pub const METH_COEXIST : c_int = 0x0040;
|
||||
|
|
|
@ -32,16 +32,13 @@ pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> c_int {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyModuleDef_Base {
|
||||
pub ob_base: PyObject,
|
||||
pub m_init: Option<extern "C" fn() -> *mut PyObject>,
|
||||
pub m_index: Py_ssize_t,
|
||||
pub m_copy: *mut PyObject,
|
||||
}
|
||||
impl Clone for PyModuleDef_Base {
|
||||
fn clone(&self) -> PyModuleDef_Base { *self }
|
||||
}
|
||||
|
||||
pub const PyModuleDef_HEAD_INIT: PyModuleDef_Base = PyModuleDef_Base {
|
||||
ob_base: PyObject_HEAD_INIT,
|
||||
|
@ -51,20 +48,17 @@ pub const PyModuleDef_HEAD_INIT: PyModuleDef_Base = PyModuleDef_Base {
|
|||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyModuleDef_Slot {
|
||||
pub slot: c_int,
|
||||
pub value: *mut c_void,
|
||||
}
|
||||
impl Clone for PyModuleDef_Slot {
|
||||
fn clone(&self) -> PyModuleDef_Slot { *self }
|
||||
}
|
||||
|
||||
pub const Py_mod_create : c_int = 1;
|
||||
pub const Py_mod_exec : c_int = 2;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyModuleDef {
|
||||
pub m_base: PyModuleDef_Base,
|
||||
pub m_name: *const c_char,
|
||||
|
@ -76,9 +70,6 @@ pub struct PyModuleDef {
|
|||
pub m_clear: Option<inquiry>,
|
||||
pub m_free: Option<freefunc>,
|
||||
}
|
||||
impl Clone for PyModuleDef {
|
||||
fn clone(&self) -> PyModuleDef { *self }
|
||||
}
|
||||
|
||||
pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef {
|
||||
m_base: PyModuleDef_HEAD_INIT,
|
||||
|
|
|
@ -93,7 +93,7 @@ mod bufferinfo {
|
|||
use ffi::pyport::Py_ssize_t;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Py_buffer {
|
||||
pub buf: *mut c_void,
|
||||
pub obj: *mut ::ffi::PyObject,
|
||||
|
@ -107,9 +107,7 @@ mod bufferinfo {
|
|||
pub suboffsets: *mut Py_ssize_t,
|
||||
pub internal: *mut c_void,
|
||||
}
|
||||
impl Clone for Py_buffer {
|
||||
#[inline] fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
impl Default for Py_buffer {
|
||||
#[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } }
|
||||
}
|
||||
|
@ -229,7 +227,7 @@ mod typeobject {
|
|||
use ffi::pyport::Py_ssize_t;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyNumberMethods {
|
||||
pub nb_add: Option<object::binaryfunc>,
|
||||
pub nb_subtract: Option<object::binaryfunc>,
|
||||
|
@ -268,9 +266,7 @@ mod typeobject {
|
|||
pub nb_matrix_multiply: Option<object::binaryfunc>,
|
||||
pub nb_inplace_matrix_multiply: Option<object::binaryfunc>,
|
||||
}
|
||||
impl Clone for PyNumberMethods {
|
||||
#[inline] fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
impl Default for PyNumberMethods {
|
||||
#[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } }
|
||||
}
|
||||
|
@ -327,7 +323,7 @@ mod typeobject {
|
|||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PySequenceMethods {
|
||||
pub sq_length: Option<object::lenfunc>,
|
||||
pub sq_concat: Option<object::binaryfunc>,
|
||||
|
@ -340,9 +336,7 @@ mod typeobject {
|
|||
pub sq_inplace_concat: Option<object::binaryfunc>,
|
||||
pub sq_inplace_repeat: Option<object::ssizeargfunc>,
|
||||
}
|
||||
impl Clone for PySequenceMethods {
|
||||
#[inline] fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
impl Default for PySequenceMethods {
|
||||
#[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } }
|
||||
}
|
||||
|
@ -359,15 +353,13 @@ mod typeobject {
|
|||
sq_inplace_repeat: None,
|
||||
};
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyMappingMethods {
|
||||
pub mp_length: Option<object::lenfunc>,
|
||||
pub mp_subscript: Option<object::binaryfunc>,
|
||||
pub mp_ass_subscript: Option<object::objobjargproc>,
|
||||
}
|
||||
impl Clone for PyMappingMethods {
|
||||
#[inline] fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
impl Default for PyMappingMethods {
|
||||
#[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } }
|
||||
}
|
||||
|
@ -377,15 +369,13 @@ mod typeobject {
|
|||
mp_ass_subscript: None,
|
||||
};
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyAsyncMethods {
|
||||
pub am_await: Option<object::unaryfunc>,
|
||||
pub am_aiter: Option<object::unaryfunc>,
|
||||
pub am_anext: Option<object::unaryfunc>,
|
||||
}
|
||||
impl Clone for PyAsyncMethods {
|
||||
#[inline] fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
impl Default for PyAsyncMethods {
|
||||
#[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } }
|
||||
}
|
||||
|
@ -395,14 +385,12 @@ mod typeobject {
|
|||
am_anext: None,
|
||||
};
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Debug)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct PyBufferProcs {
|
||||
pub bf_getbuffer: Option<object::getbufferproc>,
|
||||
pub bf_releasebuffer: Option<object::releasebufferproc>,
|
||||
}
|
||||
impl Clone for PyBufferProcs {
|
||||
#[inline] fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
impl Default for PyBufferProcs {
|
||||
#[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } }
|
||||
}
|
||||
|
@ -412,7 +400,7 @@ mod typeobject {
|
|||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyTypeObject {
|
||||
pub ob_base: object::PyVarObject,
|
||||
pub tp_name: *const c_char,
|
||||
|
@ -473,9 +461,6 @@ mod typeobject {
|
|||
#[cfg(py_sys_config="COUNT_ALLOCS")]
|
||||
pub tp_next: *mut PyTypeObject,
|
||||
}
|
||||
impl Clone for PyTypeObject {
|
||||
#[inline] fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
macro_rules! py_type_object_init {
|
||||
($tp_as_async:ident, $($tail:tt)*) => {
|
||||
|
@ -564,7 +549,7 @@ mod typeobject {
|
|||
);
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyHeapTypeObject {
|
||||
pub ht_type: PyTypeObject,
|
||||
pub as_async: PyAsyncMethods,
|
||||
|
@ -577,9 +562,7 @@ mod typeobject {
|
|||
pub ht_qualname: *mut ffi::object::PyObject,
|
||||
pub ht_cached_keys: *mut c_void,
|
||||
}
|
||||
impl Clone for PyHeapTypeObject {
|
||||
#[inline] fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
impl Default for PyHeapTypeObject {
|
||||
#[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } }
|
||||
}
|
||||
|
@ -595,20 +578,18 @@ mod typeobject {
|
|||
pub use self::typeobject::*;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyType_Slot {
|
||||
pub slot: c_int,
|
||||
pub pfunc: *mut c_void,
|
||||
}
|
||||
impl Clone for PyType_Slot {
|
||||
fn clone(&self) -> PyType_Slot { *self }
|
||||
}
|
||||
|
||||
impl Default for PyType_Slot {
|
||||
fn default() -> PyType_Slot { unsafe { ::std::mem::zeroed() } }
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyType_Spec {
|
||||
pub name: *const c_char,
|
||||
pub basicsize: c_int,
|
||||
|
@ -616,9 +597,7 @@ pub struct PyType_Spec {
|
|||
pub flags: c_uint,
|
||||
pub slots: *mut PyType_Slot,
|
||||
}
|
||||
impl Clone for PyType_Spec {
|
||||
fn clone(&self) -> PyType_Spec { *self }
|
||||
}
|
||||
|
||||
impl Default for PyType_Spec {
|
||||
fn default() -> PyType_Spec { unsafe { ::std::mem::zeroed() } }
|
||||
}
|
||||
|
@ -649,7 +628,7 @@ pub unsafe fn PyObject_TypeCheck(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_
|
|||
pub static mut PyBaseObject_Type: PyTypeObject;
|
||||
/// built-in 'super'
|
||||
pub static mut PySuper_Type: PyTypeObject;
|
||||
|
||||
|
||||
pub fn PyType_GetFlags(arg1: *mut PyTypeObject) -> c_ulong;
|
||||
}
|
||||
|
||||
|
@ -671,7 +650,7 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int {
|
|||
kwds: *mut PyObject) -> *mut PyObject;
|
||||
pub fn PyType_ClearCache() -> c_uint;
|
||||
pub fn PyType_Modified(t: *mut PyTypeObject);
|
||||
|
||||
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
pub fn PyObject_Print(o: *mut PyObject, fp: *mut ::libc::FILE, flags: c_int) -> c_int;
|
||||
pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject;
|
||||
|
|
|
@ -24,7 +24,7 @@ use ffi::object::*;
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
pub struct PyObjectArenaAllocator {
|
||||
pub ctx: *mut c_void,
|
||||
|
@ -35,10 +35,7 @@ pub struct PyObjectArenaAllocator {
|
|||
ptr: *mut c_void,
|
||||
size: size_t) -> ()>,
|
||||
}
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
impl Clone for PyObjectArenaAllocator {
|
||||
#[inline] fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
impl Default for PyObjectArenaAllocator {
|
||||
#[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } }
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::os::raw::{c_void, c_char, c_int};
|
|||
use ffi::pyport::{Py_ssize_t, Py_hash_t};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyHash_FuncDef {
|
||||
pub hash: Option<extern "C" fn(arg1: *const c_void,
|
||||
arg2: Py_ssize_t)
|
||||
|
@ -11,9 +11,7 @@ pub struct PyHash_FuncDef {
|
|||
pub hash_bits: c_int,
|
||||
pub seed_bits: c_int,
|
||||
}
|
||||
impl Clone for PyHash_FuncDef {
|
||||
#[inline] fn clone(&self) -> Self { *self }
|
||||
}
|
||||
|
||||
impl Default for PyHash_FuncDef {
|
||||
#[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } }
|
||||
}
|
||||
|
|
|
@ -3,26 +3,20 @@ use ffi::pyport::Py_ssize_t;
|
|||
use ffi::object::{PyObject, PyTypeObject};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyStructSequence_Field {
|
||||
pub name: *mut c_char,
|
||||
pub doc: *mut c_char,
|
||||
}
|
||||
impl Clone for PyStructSequence_Field {
|
||||
#[inline] fn clone(&self) -> PyStructSequence_Field { *self }
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyStructSequence_Desc {
|
||||
pub name: *mut c_char,
|
||||
pub doc: *mut c_char,
|
||||
pub fields: *mut PyStructSequence_Field,
|
||||
pub n_in_sequence: c_int,
|
||||
}
|
||||
impl Clone for PyStructSequence_Desc {
|
||||
#[inline] fn clone(&self) -> PyStructSequence_Desc { *self }
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
|
||||
pub fn PyStructSequence_NewType(desc: *mut PyStructSequence_Desc)
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
//! The vast majority of operations in this library will return `PyResult<...>`.
|
||||
//! This is an alias for the type `Result<..., PyErr>`.
|
||||
//!
|
||||
//! A `PyErr` represents a Python exception. Errors within the PyO3 library are
|
||||
//! A `PyErr` represents a Python exception. Errors within the `PyO3` library are
|
||||
//! also exposed as Python exceptions.
|
||||
//!
|
||||
//! # Example
|
||||
|
@ -132,7 +132,7 @@ pub use std::os::raw::*;
|
|||
/// Macro syntax: `py_module_initializer!($name, $py2_init, $py3_init, |$py, $m| $body)`
|
||||
///
|
||||
/// 1. `name`: The module name as a Rust identifier.
|
||||
/// 2. `py3_init`: "PyInit_" + $name. Necessary because macros can't use concat_idents!().
|
||||
/// 2. `py3_init`: "PyInit_" + $name. Necessary because macros can't use `concat_idents!()`.
|
||||
/// 4. A lambda of type `Fn(Python, &PyModule) -> PyResult<()>`.
|
||||
/// This function will be called when the module is imported, and is responsible
|
||||
/// for adding the module's members.
|
||||
|
|
|
@ -208,7 +208,7 @@ impl<T> ObjectProtocol for T where T: ToPyPointer {
|
|||
} else if result < 0 {
|
||||
return Err(PyErr::fetch(py));
|
||||
}
|
||||
return Err(PyErr::new::<::exc::TypeError, _>(py, "ObjectProtocol::compare(): All comparisons returned false"));
|
||||
Err(PyErr::new::<::exc::TypeError, _>(py, "ObjectProtocol::compare(): All comparisons returned false"))
|
||||
}
|
||||
|
||||
other.with_borrowed_ptr(py, |other| unsafe {
|
||||
|
|
|
@ -11,12 +11,12 @@ use err::{PyErr, PyResult, PyDowncastError};
|
|||
/// A python iterator object.
|
||||
///
|
||||
/// Unlike other python objects, this class includes a `Python<'p>` token
|
||||
/// so that PyIterator can implement the rust `Iterator` trait.
|
||||
/// so that `PyIterator` can implement the rust `Iterator` trait.
|
||||
pub struct PyIterator<'p>(PyPtr, Python<'p>);
|
||||
|
||||
|
||||
impl <'p> PyIterator<'p> {
|
||||
/// Constructs a PyIterator from a Python iterator object.
|
||||
/// Constructs a `PyIterator` from a Python iterator object.
|
||||
pub fn from_object<T>(py: Python<'p>, obj: T)
|
||||
-> Result<PyIterator<'p>, PyDowncastError<'p>>
|
||||
where T: IntoPyPointer
|
||||
|
@ -39,7 +39,7 @@ impl <'p> Iterator for PyIterator<'p> {
|
|||
/// Retrieves the next item from an iterator.
|
||||
/// Returns `None` when the iterator is exhausted.
|
||||
/// If an exception occurs, returns `Some(Err(..))`.
|
||||
/// Further next() calls after an exception occurs are likely
|
||||
/// Further `next()` calls after an exception occurs are likely
|
||||
/// to repeatedly result in the same exception.
|
||||
fn next(&mut self) -> Option<PyResult<PyObject>> {
|
||||
match unsafe { PyObject::from_owned_ptr_or_opt(
|
||||
|
|
|
@ -18,7 +18,7 @@ use conversion::{ToPyObject, IntoPyObject, FromPyObject};
|
|||
/// Represents a Python `int` object.
|
||||
///
|
||||
/// You can usually avoid directly working with this type
|
||||
/// by using [ToPyObject](trait.ToPyObject.html)
|
||||
/// by using [`ToPyObject`](trait.ToPyObject.html)
|
||||
/// and [extract](struct.PyObject.html#method.extract)
|
||||
/// with the primitive Rust integer types.
|
||||
pub struct PyLong(PyPtr);
|
||||
|
@ -29,7 +29,7 @@ pyobject_nativetype!(PyLong, PyLong_Check, PyLong_Type);
|
|||
/// Represents a Python `float` object.
|
||||
///
|
||||
/// You can usually avoid directly working with this type
|
||||
/// by using [ToPyObject](trait.ToPyObject.html)
|
||||
/// by using [`ToPyObject`](trait.ToPyObject.html)
|
||||
/// and [extract](struct.PyObject.html#method.extract)
|
||||
/// with `f32`/`f64`.
|
||||
pub struct PyFloat(PyPtr);
|
||||
|
@ -273,7 +273,7 @@ mod test {
|
|||
assert_eq!(v as u64, obj.extract::<u64>(py).unwrap());
|
||||
assert!(obj.extract::<i32>(py).is_err());
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_i64_max() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -284,7 +284,7 @@ mod test {
|
|||
assert_eq!(v as u64, obj.extract::<u64>(py).unwrap());
|
||||
assert!(obj.extract::<u32>(py).is_err());
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_i64_min() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -295,7 +295,7 @@ mod test {
|
|||
assert!(obj.extract::<i32>(py).is_err());
|
||||
assert!(obj.extract::<u64>(py).is_err());
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_u64_max() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
|
|
@ -10,7 +10,7 @@ use objects::PyObject;
|
|||
use conversion::ToPyObject;
|
||||
|
||||
/// Represents a Python `slice`. Only `c_long` indeces supprted
|
||||
/// at the moment by PySlice object.
|
||||
/// at the moment by `PySlice` object.
|
||||
pub struct PySlice(PyPtr);
|
||||
|
||||
pyobject_convert!(PySlice);
|
||||
|
|
|
@ -81,7 +81,7 @@ impl PyPtr {
|
|||
/// Converts `PyPtr` instance -> PyObject<'p>
|
||||
/// Consumes `self` without calling `Py_DECREF()`
|
||||
#[inline]
|
||||
pub fn into_object<'p>(self, _py: Python<'p>) -> PyObject {
|
||||
pub fn into_object(self, _py: Python) -> PyObject {
|
||||
unsafe { std::mem::transmute(self) }
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ impl PyPtr {
|
|||
/// Casts the `PyPtr` imstance to a concrete Python object type.
|
||||
/// Fails with `PyDowncastError` if the object is not of the expected type.
|
||||
#[inline]
|
||||
pub fn cast_into<'p, D>(self, py: Python<'p>) -> Result<D, PyDowncastError<'p>>
|
||||
pub fn cast_into<D>(self, py: Python) -> Result<D, PyDowncastError>
|
||||
where D: ::PyDowncastInto
|
||||
{
|
||||
<D as ::PyDowncastInto>::downcast_into(py, self)
|
||||
|
|
|
@ -93,7 +93,7 @@ pub struct GILGuard {
|
|||
no_send: marker::PhantomData<rc::Rc<()>>
|
||||
}
|
||||
|
||||
/// The Drop implementation for GILGuard will release the GIL.
|
||||
/// The Drop implementation for `GILGuard` will release the GIL.
|
||||
impl Drop for GILGuard {
|
||||
fn drop(&mut self) {
|
||||
debug!("RELEASE");
|
||||
|
|
|
@ -12,14 +12,14 @@ use typeob::{PyTypeInfo, PyObjectAlloc};
|
|||
pub struct PyToken(PhantomData<Rc<()>>);
|
||||
|
||||
impl PyToken {
|
||||
pub fn token<'p>(&'p self) -> Python<'p> {
|
||||
pub fn token(&self) -> Python {
|
||||
unsafe { Python::assume_gil_acquired() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Create new python object and move T instance under python management
|
||||
#[inline]
|
||||
pub fn init<'p, T, F>(py: Python<'p>, f: F) -> PyResult<T::Target>
|
||||
pub fn init<T, F>(py: Python, f: F) -> PyResult<T::Target>
|
||||
where F: FnOnce(PyToken) -> T,
|
||||
T: ToInstancePtr<T> + PyTypeInfo + PyObjectAlloc<T>
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ pub fn init<'p, T, F>(py: Python<'p>, f: F) -> PyResult<T::Target>
|
|||
}
|
||||
|
||||
pub trait PyObjectWithToken : Sized {
|
||||
fn token<'p>(&'p self) -> Python<'p>;
|
||||
fn token(&self) -> Python;
|
||||
}
|
||||
|
||||
pub trait ToInstancePtr<T> : Sized {
|
||||
|
|
Loading…
Reference in a new issue