Expose PyAny to lib.rs and prelude
This commit is contained in:
parent
da4009507e
commit
02ee7a5afc
|
@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||
* Bumped minimum Rust version to `1.42.0-nightly 2020-01-21`. [#761](https://github.com/PyO3/pyo3/pull/761)
|
||||
* `PyRef` and `PyRefMut` are renewed for `PyCell`. [#770](https://github.com/PyO3/pyo3/pull/770)
|
||||
* Some new FFI functions for Python 3.8. [#784](https://github.com/PyO3/pyo3/pull/784)
|
||||
* `PyAny` is now on the top level module and prelude. [#816](https://github.com/PyO3/pyo3/pull/816)
|
||||
|
||||
### Added
|
||||
* `PyCell`, which has RefCell-like features. [#770](https://github.com/PyO3/pyo3/pull/770)
|
||||
|
|
|
@ -22,7 +22,6 @@ Specifically, the following implementation is generated:
|
|||
|
||||
```rust
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyAny;
|
||||
|
||||
/// Class for demonstration
|
||||
struct MyClass {
|
||||
|
@ -326,7 +325,7 @@ that inherit native types. Even in such cases, you can unsafely get a base class
|
|||
|
||||
```rust
|
||||
# use pyo3::prelude::*;
|
||||
use pyo3::types::{PyAny, PyDict};
|
||||
use pyo3::types::PyDict;
|
||||
use pyo3::{AsPyPointer, PyNativeType};
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ let obj_ref_mut: &mut MyClass = obj.extract().unwrap();
|
|||
After:
|
||||
```
|
||||
# use pyo3::prelude::*;
|
||||
# use pyo3::types::{PyAny, IntoPyDict};
|
||||
# use pyo3::types::IntoPyDict;
|
||||
# #[pyclass] #[derive(Clone)] struct MyClass {}
|
||||
# #[pymethods] impl MyClass { #[new]fn new() -> Self { MyClass {} }}
|
||||
# let gil = Python::acquire_gil();
|
||||
|
|
|
@ -43,7 +43,7 @@ impl Default for PyClassArgs {
|
|||
// We need the 0 as value for the constant we're later building using quote for when there
|
||||
// are no other flags
|
||||
flags: vec![parse_quote! { 0 }],
|
||||
base: parse_quote! { pyo3::types::PyAny },
|
||||
base: parse_quote! { pyo3::PyAny },
|
||||
has_extends: false,
|
||||
}
|
||||
}
|
||||
|
@ -364,12 +364,12 @@ fn impl_class(
|
|||
let base_layout = if attr.has_extends {
|
||||
quote! { <Self::BaseType as pyo3::derive_utils::PyBaseTypeUtils>::LayoutAsBase }
|
||||
} else {
|
||||
quote! { pyo3::pycell::PyCellBase<pyo3::types::PyAny> }
|
||||
quote! { pyo3::pycell::PyCellBase<pyo3::PyAny> }
|
||||
};
|
||||
let base_nativetype = if attr.has_extends {
|
||||
quote! { <Self::BaseType as pyo3::derive_utils::PyBaseTypeUtils>::BaseNativeType }
|
||||
} else {
|
||||
quote! { pyo3::types::PyAny }
|
||||
quote! { pyo3::PyAny }
|
||||
};
|
||||
|
||||
// If #cls is not extended type, we allow Self->PyObject conversion
|
||||
|
|
|
@ -18,11 +18,7 @@
|
|||
|
||||
//! `PyBuffer` implementation
|
||||
use crate::err::{self, PyResult};
|
||||
use crate::exceptions;
|
||||
use crate::ffi;
|
||||
use crate::types::PyAny;
|
||||
use crate::AsPyPointer;
|
||||
use crate::Python;
|
||||
use crate::{exceptions, ffi, AsPyPointer, PyAny, Python};
|
||||
use std::ffi::CStr;
|
||||
use std::os::raw;
|
||||
use std::pin::Pin;
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
use crate::callback::{BoolCallbackConverter, HashConverter, PyObjectCallbackConverter};
|
||||
use crate::class::methods::PyMethodDef;
|
||||
use crate::err::{PyErr, PyResult};
|
||||
use crate::objectprotocol::ObjectProtocol;
|
||||
use crate::types::PyAny;
|
||||
use crate::{exceptions, ffi, FromPyObject, IntoPy, IntoPyPointer, PyClass, PyObject, Python};
|
||||
use crate::{
|
||||
exceptions, ffi, FromPyObject, IntoPy, IntoPyPointer, ObjectProtocol, PyAny, PyClass, PyErr,
|
||||
PyObject, PyResult, Python,
|
||||
};
|
||||
use std::os::raw::c_int;
|
||||
|
||||
/// Operators for the __richcmp__ method
|
||||
|
@ -232,7 +232,7 @@ where
|
|||
}
|
||||
|
||||
let slf = py.from_borrowed_ptr::<crate::PyCell<T>>(slf);
|
||||
let arg = py.from_borrowed_ptr::<crate::types::PyAny>(arg);
|
||||
let arg = py.from_borrowed_ptr::<crate::PyAny>(arg);
|
||||
call_ref_with_converter!(
|
||||
slf,
|
||||
PyObjectCallbackConverter::<T::Success>(std::marker::PhantomData),
|
||||
|
|
|
@ -90,7 +90,7 @@ macro_rules! py_binary_func {
|
|||
let py = $crate::Python::assume_gil_acquired();
|
||||
let _pool = $crate::GILPool::new(py);
|
||||
let slf = py.from_borrowed_ptr::<$crate::PyCell<T>>(slf);
|
||||
let arg = py.from_borrowed_ptr::<$crate::types::PyAny>(arg);
|
||||
let arg = py.from_borrowed_ptr::<$crate::PyAny>(arg);
|
||||
$call!(slf, $conv, py, $f, arg)
|
||||
}
|
||||
Some(wrap::<$class>)
|
||||
|
@ -111,8 +111,8 @@ macro_rules! py_binary_num_func {
|
|||
use $crate::ObjectProtocol;
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let _pool = $crate::GILPool::new(py);
|
||||
let lhs = py.from_borrowed_ptr::<$crate::types::PyAny>(lhs);
|
||||
let rhs = py.from_borrowed_ptr::<$crate::types::PyAny>(rhs);
|
||||
let lhs = py.from_borrowed_ptr::<$crate::PyAny>(lhs);
|
||||
let rhs = py.from_borrowed_ptr::<$crate::PyAny>(rhs);
|
||||
|
||||
let result = match lhs.extract() {
|
||||
Ok(lhs) => match rhs.extract() {
|
||||
|
@ -144,7 +144,7 @@ macro_rules! py_binary_self_func {
|
|||
let py = $crate::Python::assume_gil_acquired();
|
||||
let _pool = $crate::GILPool::new(py);
|
||||
let slf_ = py.from_borrowed_ptr::<$crate::PyCell<T>>(slf);
|
||||
let arg = py.from_borrowed_ptr::<$crate::types::PyAny>(arg);
|
||||
let arg = py.from_borrowed_ptr::<$crate::PyAny>(arg);
|
||||
let result = call_mut!(slf_, $f, arg);
|
||||
match result {
|
||||
Ok(_) => {
|
||||
|
@ -207,8 +207,8 @@ macro_rules! py_ternary_func {
|
|||
let py = $crate::Python::assume_gil_acquired();
|
||||
let _pool = $crate::GILPool::new(py);
|
||||
let slf = py.from_borrowed_ptr::<$crate::PyCell<T>>(slf);
|
||||
let arg1 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg1);
|
||||
let arg2 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg2);
|
||||
let arg1 = py.from_borrowed_ptr::<$crate::PyAny>(arg1);
|
||||
let arg2 = py.from_borrowed_ptr::<$crate::PyAny>(arg2);
|
||||
|
||||
call_ref_with_converter!(slf, $conv, py, $f, arg1, arg2)
|
||||
}
|
||||
|
@ -233,9 +233,9 @@ macro_rules! py_ternary_num_func {
|
|||
|
||||
let py = $crate::Python::assume_gil_acquired();
|
||||
let _pool = $crate::GILPool::new(py);
|
||||
let arg1 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg1);
|
||||
let arg2 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg2);
|
||||
let arg3 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg3);
|
||||
let arg1 = py.from_borrowed_ptr::<$crate::PyAny>(arg1);
|
||||
let arg2 = py.from_borrowed_ptr::<$crate::PyAny>(arg2);
|
||||
let arg3 = py.from_borrowed_ptr::<$crate::PyAny>(arg3);
|
||||
|
||||
let result = match arg1.extract() {
|
||||
Ok(arg1) => match arg2.extract() {
|
||||
|
@ -271,8 +271,8 @@ macro_rules! py_ternary_self_func {
|
|||
let py = $crate::Python::assume_gil_acquired();
|
||||
let _pool = $crate::GILPool::new(py);
|
||||
let slf_cell = py.from_borrowed_ptr::<$crate::PyCell<T>>(slf);
|
||||
let arg1 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg1);
|
||||
let arg2 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg2);
|
||||
let arg1 = py.from_borrowed_ptr::<$crate::PyAny>(arg1);
|
||||
let arg2 = py.from_borrowed_ptr::<$crate::PyAny>(arg2);
|
||||
let result = call_mut!(slf_cell, $f, arg1, arg2);
|
||||
match result {
|
||||
Ok(_) => slf,
|
||||
|
@ -307,8 +307,8 @@ macro_rules! py_func_set {
|
|||
),
|
||||
))
|
||||
} else {
|
||||
let name = py.from_borrowed_ptr::<$crate::types::PyAny>(name);
|
||||
let value = py.from_borrowed_ptr::<$crate::types::PyAny>(value);
|
||||
let name = py.from_borrowed_ptr::<$crate::PyAny>(name);
|
||||
let value = py.from_borrowed_ptr::<$crate::PyAny>(value);
|
||||
call_mut!(slf, $fn_set, name, value)
|
||||
};
|
||||
match result {
|
||||
|
@ -338,7 +338,7 @@ macro_rules! py_func_del {
|
|||
|
||||
let result = if value.is_null() {
|
||||
let slf = py.from_borrowed_ptr::<$crate::PyCell<U>>(slf);
|
||||
let name = py.from_borrowed_ptr::<$crate::types::PyAny>(name);
|
||||
let name = py.from_borrowed_ptr::<$crate::PyAny>(name);
|
||||
|
||||
call_mut!(slf, $fn_del, name)
|
||||
} else {
|
||||
|
@ -371,12 +371,12 @@ macro_rules! py_func_set_del {
|
|||
let py = $crate::Python::assume_gil_acquired();
|
||||
let _pool = $crate::GILPool::new(py);
|
||||
let slf = py.from_borrowed_ptr::<$crate::PyCell<$generic>>(slf);
|
||||
let name = py.from_borrowed_ptr::<$crate::types::PyAny>(name);
|
||||
let name = py.from_borrowed_ptr::<$crate::PyAny>(name);
|
||||
|
||||
let result = if value.is_null() {
|
||||
call_mut!(slf, $fn_del, name)
|
||||
} else {
|
||||
let value = py.from_borrowed_ptr::<$crate::types::PyAny>(value);
|
||||
let value = py.from_borrowed_ptr::<$crate::PyAny>(value);
|
||||
call_mut!(slf, $fn_set, name, value)
|
||||
};
|
||||
match result {
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
use crate::callback::{BoolCallbackConverter, LenResultConverter, PyObjectCallbackConverter};
|
||||
use crate::err::{PyErr, PyResult};
|
||||
use crate::objectprotocol::ObjectProtocol;
|
||||
use crate::types::PyAny;
|
||||
use crate::{exceptions, ffi, FromPyObject, IntoPy, PyClass, PyObject, Python};
|
||||
use crate::{exceptions, ffi, FromPyObject, IntoPy, PyAny, PyClass, PyObject, Python};
|
||||
use std::os::raw::c_int;
|
||||
|
||||
/// Sequence interface
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
use crate::err::{self, PyDowncastError, PyResult};
|
||||
use crate::object::PyObject;
|
||||
use crate::type_object::{PyDowncastImpl, PyTypeInfo};
|
||||
use crate::types::PyAny;
|
||||
use crate::types::PyTuple;
|
||||
use crate::{ffi, gil, Py, PyCell, PyClass, PyNativeType, PyRef, PyRefMut, Python};
|
||||
use crate::{ffi, gil, Py, PyAny, PyCell, PyClass, PyNativeType, PyRef, PyRefMut, Python};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
/// This trait represents that **we can do zero-cost conversion from the object
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
//! Interaction with python's global interpreter lock
|
||||
|
||||
use crate::ffi;
|
||||
use crate::internal_tricks::Unsendable;
|
||||
use crate::types::PyAny;
|
||||
use crate::Python;
|
||||
use crate::{ffi, internal_tricks::Unsendable, PyAny, Python};
|
||||
use std::ptr::NonNull;
|
||||
use std::{any, sync};
|
||||
|
||||
|
|
|
@ -4,10 +4,9 @@ use crate::gil;
|
|||
use crate::object::PyObject;
|
||||
use crate::objectprotocol::ObjectProtocol;
|
||||
use crate::type_object::{PyBorrowFlagLayout, PyDowncastImpl};
|
||||
use crate::types::PyAny;
|
||||
use crate::{
|
||||
ffi, AsPyPointer, FromPyObject, IntoPy, IntoPyPointer, PyCell, PyClass, PyClassInitializer,
|
||||
PyRef, PyRefMut, PyTypeInfo, Python, ToPyObject,
|
||||
ffi, AsPyPointer, FromPyObject, IntoPy, IntoPyPointer, PyAny, PyCell, PyClass,
|
||||
PyClassInitializer, PyRef, PyRefMut, PyTypeInfo, Python, ToPyObject,
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
|
|
|
@ -148,6 +148,8 @@ pub use crate::pyclass::PyClass;
|
|||
pub use crate::pyclass_init::PyClassInitializer;
|
||||
pub use crate::python::{prepare_freethreaded_python, Python};
|
||||
pub use crate::type_object::{type_flags, PyTypeInfo};
|
||||
// Since PyAny is as important as PyObject, we expose it to the top level.
|
||||
pub use crate::types::PyAny;
|
||||
|
||||
// Re-exported for wrap_function
|
||||
#[doc(hidden)]
|
||||
|
|
|
@ -19,7 +19,7 @@ pub use crate::pycell::{PyCell, PyRef, PyRefMut};
|
|||
pub use crate::pyclass_init::PyClassInitializer;
|
||||
pub use crate::python::Python;
|
||||
pub use crate::{FromPy, FromPyObject, IntoPy, IntoPyPointer, PyTryFrom, PyTryInto, ToPyObject};
|
||||
// This is only part of the prelude because we need it for the pymodule function
|
||||
pub use crate::types::PyModule;
|
||||
// PyModule is only part of the prelude because we need it for the pymodule function
|
||||
pub use crate::types::{PyAny, PyModule};
|
||||
pub use pyo3cls::pymodule;
|
||||
pub use pyo3cls::{pyclass, pyfunction, pymethods, pyproto};
|
||||
|
|
|
@ -3,8 +3,7 @@ use crate::conversion::{AsPyPointer, FromPyPointer, ToPyObject};
|
|||
use crate::pyclass_init::PyClassInitializer;
|
||||
use crate::pyclass_slots::{PyClassDict, PyClassWeakRef};
|
||||
use crate::type_object::{PyBorrowFlagLayout, PyDowncastImpl, PyLayout, PySizedLayout, PyTypeInfo};
|
||||
use crate::types::PyAny;
|
||||
use crate::{ffi, FromPy, PyClass, PyErr, PyNativeType, PyObject, PyResult, Python};
|
||||
use crate::{ffi, FromPy, PyAny, PyClass, PyErr, PyNativeType, PyObject, PyResult, Python};
|
||||
use std::cell::{Cell, UnsafeCell};
|
||||
use std::fmt;
|
||||
use std::mem::ManuallyDrop;
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||
use crate::ffi;
|
||||
use crate::internal_tricks::Unsendable;
|
||||
use crate::object::PyObject;
|
||||
use crate::types::PyAny;
|
||||
use crate::FromPyObject;
|
||||
use crate::PyResult;
|
||||
use crate::Python;
|
||||
use crate::{AsPyPointer, FromPy};
|
||||
use crate::{PyTryFrom, ToPyObject};
|
||||
use crate::{
|
||||
ffi, AsPyPointer, FromPy, FromPyObject, PyAny, PyObject, PyResult, PyTryFrom, Python,
|
||||
ToPyObject,
|
||||
};
|
||||
|
||||
/// Represents a Python `bool`.
|
||||
#[repr(transparent)]
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
use crate::conversion::FromPyObject;
|
||||
use crate::conversion::{PyTryFrom, ToPyObject};
|
||||
use crate::err::PyResult;
|
||||
use crate::internal_tricks::Unsendable;
|
||||
use crate::object::PyObject;
|
||||
use crate::types::PyAny;
|
||||
use crate::AsPyPointer;
|
||||
use crate::Python;
|
||||
use crate::{ffi, FromPy};
|
||||
use crate::{
|
||||
ffi, AsPyPointer, FromPy, FromPyObject, PyAny, PyObject, PyResult, PyTryFrom, Python,
|
||||
ToPyObject,
|
||||
};
|
||||
use std::ops::Index;
|
||||
use std::os::raw::c_char;
|
||||
use std::slice::SliceIndex;
|
||||
|
|
|
@ -133,10 +133,7 @@ impl<'py> Neg for &'py PyComplex {
|
|||
#[cfg(feature = "num-complex")]
|
||||
mod complex_conversion {
|
||||
use super::*;
|
||||
use crate::err::PyErr;
|
||||
use crate::types::PyAny;
|
||||
use crate::PyResult;
|
||||
use crate::{FromPyObject, ToPyObject};
|
||||
use crate::{FromPyObject, PyAny, PyErr, PyResult, ToPyObject};
|
||||
use num_complex::Complex;
|
||||
|
||||
impl PyComplex {
|
||||
|
|
|
@ -1,19 +1,11 @@
|
|||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||
//
|
||||
// based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython
|
||||
|
||||
use crate::err::PyErr;
|
||||
use crate::ffi;
|
||||
use crate::instance::PyNativeType;
|
||||
use crate::internal_tricks::Unsendable;
|
||||
use crate::object::PyObject;
|
||||
use crate::objectprotocol::ObjectProtocol;
|
||||
use crate::types::PyAny;
|
||||
use crate::FromPyObject;
|
||||
use crate::PyResult;
|
||||
use crate::Python;
|
||||
use crate::ToPyObject;
|
||||
use crate::{AsPyPointer, FromPy};
|
||||
use crate::{
|
||||
ffi, AsPyPointer, FromPy, FromPyObject, ObjectProtocol, PyAny, PyErr, PyNativeType, PyObject,
|
||||
PyResult, Python, ToPyObject,
|
||||
};
|
||||
use std::os::raw::c_double;
|
||||
|
||||
/// Represents a Python `float` object.
|
||||
|
|
|
@ -2,12 +2,7 @@
|
|||
//
|
||||
// based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython
|
||||
|
||||
use crate::err::{PyDowncastError, PyErr, PyResult};
|
||||
use crate::ffi;
|
||||
use crate::instance::PyNativeType;
|
||||
use crate::types::PyAny;
|
||||
use crate::AsPyPointer;
|
||||
use crate::Python;
|
||||
use crate::{ffi, AsPyPointer, PyAny, PyDowncastError, PyErr, PyNativeType, PyResult, Python};
|
||||
|
||||
/// A Python iterator object.
|
||||
///
|
||||
|
|
|
@ -4,14 +4,11 @@
|
|||
|
||||
use crate::err::{self, PyResult};
|
||||
use crate::ffi::{self, Py_ssize_t};
|
||||
use crate::instance::PyNativeType;
|
||||
use crate::internal_tricks::Unsendable;
|
||||
use crate::object::PyObject;
|
||||
use crate::types::PyAny;
|
||||
use crate::IntoPyPointer;
|
||||
use crate::Python;
|
||||
use crate::{AsPyPointer, IntoPy};
|
||||
use crate::{ToBorrowedObject, ToPyObject};
|
||||
use crate::{
|
||||
AsPyPointer, IntoPy, IntoPyPointer, PyAny, PyNativeType, PyObject, Python, ToBorrowedObject,
|
||||
ToPyObject,
|
||||
};
|
||||
|
||||
/// Represents a Python `list`.
|
||||
#[repr(transparent)]
|
||||
|
|
|
@ -28,10 +28,10 @@ pub use self::typeobject::PyType;
|
|||
#[macro_export]
|
||||
macro_rules! pyobject_native_type_named (
|
||||
($name: ty $(,$type_param: ident)*) => {
|
||||
impl<$($type_param,)*> ::std::convert::AsRef<$crate::types::PyAny> for $name {
|
||||
impl<$($type_param,)*> ::std::convert::AsRef<$crate::PyAny> for $name {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &$crate::types::PyAny {
|
||||
unsafe{&*(self as *const $name as *const $crate::types::PyAny)}
|
||||
fn as_ref(&self) -> &$crate::PyAny {
|
||||
unsafe{&*(self as *const $name as *const $crate::PyAny)}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,9 +71,9 @@ macro_rules! pyobject_native_type {
|
|||
pyobject_native_type_convert!($name, $layout, $typeobject, $module, $checkfunction $(,$type_param)*);
|
||||
pyobject_native_type_extract!($name $(,$type_param)*);
|
||||
|
||||
impl<'a, $($type_param,)*> ::std::convert::From<&'a $name> for &'a $crate::types::PyAny {
|
||||
impl<'a, $($type_param,)*> ::std::convert::From<&'a $name> for &'a $crate::PyAny {
|
||||
fn from(ob: &'a $name) -> Self {
|
||||
unsafe{&*(ob as *const $name as *const $crate::types::PyAny)}
|
||||
unsafe{&*(ob as *const $name as *const $crate::PyAny)}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -93,9 +93,9 @@ macro_rules! pyobject_native_var_type {
|
|||
$typeobject, $module, $checkfunction $(,$type_param)*);
|
||||
pyobject_native_type_extract!($name $(,$type_param)*);
|
||||
|
||||
impl<'a, $($type_param,)*> ::std::convert::From<&'a $name> for &'a $crate::types::PyAny {
|
||||
impl<'a, $($type_param,)*> ::std::convert::From<&'a $name> for &'a $crate::PyAny {
|
||||
fn from(ob: &'a $name) -> Self {
|
||||
unsafe{&*(ob as *const $name as *const $crate::types::PyAny)}
|
||||
unsafe{&*(ob as *const $name as *const $crate::PyAny)}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -111,7 +111,7 @@ macro_rules! pyobject_native_var_type {
|
|||
macro_rules! pyobject_native_type_extract {
|
||||
($name: ty $(,$type_param: ident)*) => {
|
||||
impl<'py, $($type_param,)*> $crate::FromPyObject<'py> for &'py $name {
|
||||
fn extract(obj: &'py crate::types::PyAny) -> $crate::PyResult<Self> {
|
||||
fn extract(obj: &'py $crate::PyAny) -> $crate::PyResult<Self> {
|
||||
$crate::PyTryFrom::try_from(obj).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ macro_rules! pyobject_native_type_convert(
|
|||
$module: expr, $checkfunction: path $(,$type_param: ident)*) => {
|
||||
unsafe impl<$($type_param,)*> $crate::type_object::PyTypeInfo for $name {
|
||||
type Type = ();
|
||||
type BaseType = $crate::types::PyAny;
|
||||
type BaseType = $crate::PyAny;
|
||||
type Layout = $layout;
|
||||
type BaseLayout = ffi::PyObject;
|
||||
type Initializer = $crate::pyclass_init::PyNativeTypeInitializer<Self>;
|
||||
|
@ -139,7 +139,7 @@ macro_rules! pyobject_native_type_convert(
|
|||
}
|
||||
|
||||
#[allow(unused_unsafe)]
|
||||
fn is_instance(ptr: &$crate::types::PyAny) -> bool {
|
||||
fn is_instance(ptr: &$crate::PyAny) -> bool {
|
||||
use $crate::AsPyPointer;
|
||||
unsafe { $checkfunction(ptr.as_ptr()) > 0 }
|
||||
}
|
||||
|
|
|
@ -2,21 +2,14 @@
|
|||
//
|
||||
// based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython
|
||||
|
||||
use crate::err::{PyErr, PyResult};
|
||||
use crate::exceptions;
|
||||
use crate::ffi;
|
||||
use crate::instance::PyNativeType;
|
||||
use crate::internal_tricks::Unsendable;
|
||||
use crate::object::PyObject;
|
||||
use crate::types::PyAny;
|
||||
use crate::AsPyPointer;
|
||||
use crate::IntoPy;
|
||||
use crate::Python;
|
||||
use crate::{FromPyObject, ToPyObject};
|
||||
use crate::{
|
||||
exceptions, ffi, AsPyPointer, FromPyObject, IntoPy, PyAny, PyErr, PyNativeType, PyObject,
|
||||
PyResult, Python, ToPyObject,
|
||||
};
|
||||
use num_traits::cast::cast;
|
||||
use std::i64;
|
||||
use std::os::raw::c_int;
|
||||
use std::os::raw::{c_long, c_uchar};
|
||||
use std::os::raw::{c_int, c_long, c_uchar};
|
||||
|
||||
fn err_if_invalid_value<T: PartialEq>(
|
||||
py: Python,
|
||||
|
|
|
@ -2,16 +2,11 @@
|
|||
//
|
||||
|
||||
use crate::err::{self, PyErr, PyResult};
|
||||
use crate::ffi;
|
||||
use crate::instance::PyNativeType;
|
||||
use crate::internal_tricks::Unsendable;
|
||||
use crate::object::PyObject;
|
||||
use crate::types::PyAny;
|
||||
use crate::AsPyPointer;
|
||||
use crate::Python;
|
||||
use crate::{ToBorrowedObject, ToPyObject};
|
||||
use std::ptr;
|
||||
use std::{collections, hash};
|
||||
use crate::{
|
||||
ffi, AsPyPointer, PyAny, PyNativeType, PyObject, Python, ToBorrowedObject, ToPyObject,
|
||||
};
|
||||
use std::{collections, hash, ptr};
|
||||
|
||||
/// Represents a Python `set`
|
||||
#[repr(transparent)]
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||
|
||||
use crate::conversion::FromPyObject;
|
||||
use crate::conversion::{PyTryFrom, ToPyObject};
|
||||
use crate::err::{PyErr, PyResult};
|
||||
use crate::instance::PyNativeType;
|
||||
use crate::internal_tricks::Unsendable;
|
||||
use crate::object::PyObject;
|
||||
use crate::types::PyAny;
|
||||
use crate::{ffi, gil, AsPyPointer, FromPy, IntoPy, Python};
|
||||
use crate::{
|
||||
ffi, gil, AsPyPointer, FromPy, FromPyObject, IntoPy, PyAny, PyErr, PyNativeType, PyObject,
|
||||
PyResult, PyTryFrom, Python, ToPyObject,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
use std::ffi::CStr;
|
||||
use std::os::raw::c_char;
|
||||
|
|
|
@ -1,17 +1,11 @@
|
|||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||
|
||||
use crate::conversion::FromPy;
|
||||
use crate::err::{PyErr, PyResult};
|
||||
use crate::exceptions;
|
||||
use crate::ffi::{self, Py_ssize_t};
|
||||
use crate::instance::{AsPyRef, Py, PyNativeType};
|
||||
use crate::internal_tricks::Unsendable;
|
||||
use crate::object::PyObject;
|
||||
use crate::types::PyAny;
|
||||
use crate::AsPyPointer;
|
||||
use crate::IntoPyPointer;
|
||||
use crate::Python;
|
||||
use crate::{FromPyObject, IntoPy, PyTryFrom, ToPyObject};
|
||||
use crate::{
|
||||
exceptions, AsPyPointer, AsPyRef, FromPy, FromPyObject, IntoPy, IntoPyPointer, Py, PyAny,
|
||||
PyErr, PyNativeType, PyObject, PyResult, PyTryFrom, Python, ToPyObject,
|
||||
};
|
||||
use std::slice;
|
||||
|
||||
/// Represents a Python `tuple` object.
|
||||
|
@ -256,12 +250,8 @@ tuple_conversion!(
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::instance::AsPyRef;
|
||||
use crate::objectprotocol::ObjectProtocol;
|
||||
use crate::types::PyAny;
|
||||
use crate::types::PyTuple;
|
||||
use crate::Python;
|
||||
use crate::{PyTryFrom, ToPyObject};
|
||||
use crate::types::{PyAny, PyTuple};
|
||||
use crate::{AsPyRef, ObjectProtocol, PyTryFrom, Python, ToPyObject};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[test]
|
||||
|
|
1
tests/test_arithmetics.rs
Normal file → Executable file
1
tests/test_arithmetics.rs
Normal file → Executable file
|
@ -4,7 +4,6 @@ use pyo3::class::basic::CompareOp;
|
|||
use pyo3::class::*;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::py_run;
|
||||
use pyo3::types::PyAny;
|
||||
|
||||
mod common;
|
||||
|
||||
|
|
2
tests/test_datetime.rs
Normal file → Executable file
2
tests/test_datetime.rs
Normal file → Executable file
|
@ -2,7 +2,7 @@
|
|||
|
||||
use pyo3::ffi::*;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::{IntoPyDict, PyAny};
|
||||
use pyo3::types::IntoPyDict;
|
||||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
fn _get_subclasses<'p>(
|
||||
|
|
2
tests/test_dunder.rs
Normal file → Executable file
2
tests/test_dunder.rs
Normal file → Executable file
|
@ -5,7 +5,7 @@ use pyo3::class::{
|
|||
};
|
||||
use pyo3::exceptions::{IndexError, ValueError};
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::{IntoPyDict, PyAny, PyBytes, PySlice, PyType};
|
||||
use pyo3::types::{IntoPyDict, PyBytes, PySlice, PyType};
|
||||
use pyo3::{ffi, py_run, AsPyPointer, PyCell};
|
||||
use std::convert::TryFrom;
|
||||
use std::{isize, iter};
|
||||
|
|
|
@ -2,7 +2,7 @@ use pyo3::class::PyGCProtocol;
|
|||
use pyo3::class::PyTraverseError;
|
||||
use pyo3::class::PyVisit;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::{PyAny, PyTuple};
|
||||
use pyo3::types::PyTuple;
|
||||
use pyo3::{ffi, py_run, AsPyPointer, PyCell, PyTryInto};
|
||||
use std::cell::RefCell;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
|
|
@ -39,7 +39,7 @@ impl BaseClass {
|
|||
fn base_method(&self, x: usize) -> usize {
|
||||
x * self.val1
|
||||
}
|
||||
fn base_set(&mut self, fn_: &pyo3::types::PyAny) -> PyResult<()> {
|
||||
fn base_set(&mut self, fn_: &pyo3::PyAny) -> PyResult<()> {
|
||||
let value: usize = fn_.call0()?.extract()?;
|
||||
self.val1 = value;
|
||||
Ok(())
|
||||
|
|
|
@ -2,9 +2,7 @@ use pyo3::class::PySequenceProtocol;
|
|||
use pyo3::exceptions::IndexError;
|
||||
use pyo3::exceptions::ValueError;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::IntoPyDict;
|
||||
use pyo3::types::PyAny;
|
||||
use pyo3::types::PyList;
|
||||
use pyo3::types::{IntoPyDict, PyList};
|
||||
|
||||
#[pyclass]
|
||||
struct ByteSequence {
|
||||
|
|
Loading…
Reference in a new issue