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