1pub use self::any::{PyAny, PyAnyMethods};
4pub use self::boolobject::{PyBool, PyBoolMethods};
5pub use self::bytearray::{PyByteArray, PyByteArrayMethods};
6pub use self::bytes::{PyBytes, PyBytesMethods};
7pub use self::capsule::{CapsuleName, PyCapsule, PyCapsuleMethods};
8pub use self::code::{PyCode, PyCodeInput, PyCodeMethods};
9pub use self::complex::{PyComplex, PyComplexMethods};
10pub use self::datetime::{PyDate, PyDateTime, PyDelta, PyTime, PyTzInfo, PyTzInfoAccess};
11#[cfg(not(Py_LIMITED_API))]
12pub use self::datetime::{PyDateAccess, PyDeltaAccess, PyTimeAccess};
13pub use self::dict::{IntoPyDict, PyDict, PyDictMethods};
14#[cfg(not(any(PyPy, GraalPy, RustPython)))]
15pub use self::dict::{PyDictItems, PyDictKeys, PyDictValues};
16pub use self::ellipsis::PyEllipsis;
17pub use self::float::{PyFloat, PyFloatMethods};
18#[cfg(all(not(Py_LIMITED_API), not(PyPy), not(GraalPy)))]
19pub use self::frame::{PyFrame, PyFrameMethods};
20pub use self::frozenset::{PyFrozenSet, PyFrozenSetBuilder, PyFrozenSetMethods};
21pub use self::function::PyCFunction;
22#[cfg(not(Py_LIMITED_API))]
23pub use self::function::PyFunction;
24#[cfg(Py_3_9)]
25pub use self::genericalias::PyGenericAlias;
26pub use self::iterator::PyIterator;
27#[cfg(all(not(PyPy), Py_3_10))]
28pub use self::iterator::PySendResult;
29pub use self::list::{PyList, PyListMethods};
30pub use self::mapping::{PyMapping, PyMappingMethods};
31pub use self::mappingproxy::PyMappingProxy;
32pub use self::memoryview::PyMemoryView;
33pub use self::module::{PyModule, PyModuleMethods};
34#[cfg(all(not(Py_LIMITED_API), Py_3_13))]
35pub use self::mutex::{PyMutex, PyMutexGuard};
36pub use self::none::PyNone;
37pub use self::notimplemented::PyNotImplemented;
38pub use self::num::PyInt;
39pub use self::pysuper::PySuper;
40pub use self::range::{PyRange, PyRangeMethods};
41pub use self::sequence::{PySequence, PySequenceMethods};
42pub use self::set::{PySet, PySetMethods};
43pub use self::slice::{PySlice, PySliceIndices, PySliceMethods};
44#[cfg(not(Py_LIMITED_API))]
45pub use self::string::PyStringData;
46pub use self::string::{PyString, PyStringMethods};
47pub use self::traceback::{PyTraceback, PyTracebackMethods};
48pub use self::tuple::{PyTuple, PyTupleMethods};
49pub use self::typeobject::{PyType, PyTypeMethods};
50pub use self::weakref::{PyWeakref, PyWeakrefMethods, PyWeakrefProxy, PyWeakrefReference};
51
52pub mod iter {
83 pub use super::dict::BoundDictIterator;
84 pub use super::frozenset::BoundFrozenSetIterator;
85 pub use super::list::BoundListIterator;
86 pub use super::set::BoundSetIterator;
87 pub use super::tuple::{BorrowedTupleIterator, BoundTupleIterator};
88}
89
90pub trait DerefToPyAny {
112 }
114
115#[doc(hidden)]
118#[macro_export]
119macro_rules! pyobject_native_type_named (
120 ($name:ty $(;$generics:ident)*) => {
121 impl $crate::types::DerefToPyAny for $name {}
122 };
123);
124
125#[doc(hidden)]
131#[macro_export]
132macro_rules! pyobject_native_static_type_object(
133 ($typeobject:expr) => {
134 |_py| &raw mut $typeobject
135 };
136);
137
138#[cfg(not(feature = "experimental-inspect"))]
140#[doc(hidden)]
141#[macro_export]
142macro_rules! pyobject_type_info_type_hint(
143 ($module:expr, $name:expr) => {};
144);
145
146#[cfg(feature = "experimental-inspect")]
147#[doc(hidden)]
148#[macro_export]
149macro_rules! pyobject_type_info_type_hint(
150 ($module:expr, $name:expr) => {
151 const TYPE_HINT: $crate::inspect::PyStaticExpr = $crate::type_hint_identifier!($module, $name);
152 };
153);
154
155#[doc(hidden)]
163#[macro_export]
164macro_rules! pyobject_native_type_info(
165 ($name:ty, $typeobject:expr, $type_hint_module:expr, $type_hint_name:expr, $module:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
166 unsafe impl<$($generics,)*> $crate::type_object::PyTypeInfo for $name {
168 const NAME: &'static str = stringify!($name);
169 const MODULE: ::core::option::Option<&'static str> = $module;
170 $crate::pyobject_type_info_type_hint!($type_hint_module, $type_hint_name);
171
172 #[inline]
173 #[allow(clippy::redundant_closure_call)]
174 fn type_object_raw(py: $crate::Python<'_>) -> *mut $crate::ffi::PyTypeObject {
175 $typeobject(py)
176 }
177
178 $(
179 #[inline]
180 fn is_type_of(obj: &$crate::Bound<'_, $crate::PyAny>) -> bool {
181 #[allow(unused_unsafe, reason = "not all `$checkfunction` are unsafe fn")]
182 unsafe { $checkfunction(obj.as_ptr()) > 0 }
184 }
185 )?
186 }
187
188 impl $name {
189 #[doc(hidden)]
190 pub const _PYO3_DEF: $crate::impl_::pymodule::AddTypeToModule<Self> = $crate::impl_::pymodule::AddTypeToModule::new();
191
192 #[allow(dead_code)]
193 #[doc(hidden)]
194 pub const _PYO3_INTROSPECTION_ID: &'static str = concat!(stringify!($module), stringify!($name));
195 }
196 };
197);
198
199#[doc(hidden)]
201#[macro_export]
202macro_rules! pyobject_native_type_core {
203 ($name:ty, $typeobject:expr, $type_hint_module:expr, $type_hint_name:expr, #module=$module:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
204 $crate::pyobject_native_type_named!($name $(;$generics)*);
205 $crate::pyobject_native_type_info!($name, $typeobject, $type_hint_module, $type_hint_name, $module $(, #checkfunction=$checkfunction)? $(;$generics)*);
206 };
207 ($name:ty, $typeobject:expr, $type_hint_module:expr, $type_hint_name:expr, #module=$module:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
208 $crate::pyobject_native_type_core!($name, $typeobject, $type_hint_module, $type_hint_name, #module=$module $(, #checkfunction=$checkfunction)? $(;$generics)*);
209 };
210 ($name:ty, $typeobject:expr, $type_hint_module:expr, $type_hint_name:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
211 $crate::pyobject_native_type_core!($name, $typeobject, $type_hint_module, $type_hint_name, #module=::core::option::Option::Some("builtins") $(, #checkfunction=$checkfunction)? $(;$generics)*);
212 };
213}
214
215#[doc(hidden)]
216#[macro_export]
217macro_rules! pyobject_subclassable_native_type {
218 ($name:ty, $layout:path $(;$generics:ident)*) => {
219 #[cfg(not(Py_LIMITED_API))]
220 impl<$($generics,)*> $crate::impl_::pyclass::PyClassBaseType for $name {
221 type LayoutAsBase = $crate::impl_::pycell::PyClassObjectBase<$layout>;
222 type BaseNativeType = $name;
223 type Initializer = $crate::impl_::pyclass_init::PyNativeTypeInitializer<Self>;
224 type PyClassMutability = $crate::pycell::impl_::ImmutableClass;
225 type Layout<T: $crate::impl_::pyclass::PyClassImpl> = $crate::impl_::pycell::PyStaticClassObject<T>;
226 }
227
228 #[cfg(all(Py_3_12, Py_LIMITED_API))]
229 impl<$($generics,)*> $crate::impl_::pyclass::PyClassBaseType for $name {
230 type LayoutAsBase = $crate::impl_::pycell::PyVariableClassObjectBase;
231 type BaseNativeType = Self;
232 type Initializer = $crate::impl_::pyclass_init::PyNativeTypeInitializer<Self>;
233 type PyClassMutability = $crate::pycell::impl_::ImmutableClass;
234 type Layout<T: $crate::impl_::pyclass::PyClassImpl> = $crate::impl_::pycell::PyVariableClassObject<T>;
235 }
236 }
237}
238
239#[doc(hidden)]
240#[macro_export]
241macro_rules! pyobject_native_type_sized {
242 ($name:ty, $layout:path $(;$generics:ident)*) => {
243 unsafe impl $crate::type_object::PyLayout<$name> for $layout {}
244 impl $crate::type_object::PySizedLayout<$name> for $layout {}
245 };
246}
247
248#[doc(hidden)]
251#[macro_export]
252macro_rules! pyobject_native_type {
253 ($name:ty, $layout:path, $typeobject:expr, $type_hint_module:expr, $type_hint_name:expr $(, #module=$module:expr)? $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => {
254 $crate::pyobject_native_type_core!($name, $typeobject, $type_hint_module, $type_hint_name $(, #module=$module)? $(, #checkfunction=$checkfunction)? $(;$generics)*);
255 #[cfg(not(Py_LIMITED_API))]
257 $crate::pyobject_native_type_sized!($name, $layout $(;$generics)*);
258 };
259}
260
261pub(crate) mod any;
262pub(crate) mod boolobject;
263pub(crate) mod bytearray;
264pub(crate) mod bytes;
265pub(crate) mod capsule;
266mod code;
267pub(crate) mod complex;
268pub(crate) mod datetime;
269pub(crate) mod dict;
270mod ellipsis;
271pub(crate) mod float;
272#[cfg(all(not(Py_LIMITED_API), not(PyPy), not(GraalPy)))]
273mod frame;
274pub(crate) mod frozenset;
275mod function;
276#[cfg(Py_3_9)]
277pub(crate) mod genericalias;
278pub(crate) mod iterator;
279pub(crate) mod list;
280pub(crate) mod mapping;
281pub(crate) mod mappingproxy;
282mod memoryview;
283pub(crate) mod module;
284#[cfg(all(not(Py_LIMITED_API), Py_3_13))]
285mod mutex;
286mod none;
287mod notimplemented;
288mod num;
289mod pysuper;
290pub(crate) mod range;
291pub(crate) mod sequence;
292pub(crate) mod set;
293pub(crate) mod slice;
294pub(crate) mod string;
295pub(crate) mod traceback;
296pub(crate) mod tuple;
297pub(crate) mod typeobject;
298pub(crate) mod weakref;