diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 6be185c..09550a4 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -84,5 +84,7 @@ jobs: override: true - uses: taiki-e/install-action@v1 with: - tool: cargo-hack@0.6.28,cargo-make + # cargo-expand does not have stable output, so changing the version, + # while fine, will produce test case noise + tool: cargo-hack@0.6.28,cargo-make,cargo-expand@1.0.88 - run: cargo make test diff --git a/Cargo.toml b/Cargo.toml index a4b0e7e..52dcca4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,3 +32,4 @@ indexmap = { version = "2.0.0", optional = true } [dev-dependencies] thiserror = "1.0" +macrotest = "1.0.13" diff --git a/src/lib.rs b/src/lib.rs index 29356cb..250ad7c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -198,6 +198,7 @@ impl PyWrapperMut for T where T: PyWrapper + AsMut {} /// } /// /// create_init_submodule! { +/// /// Initialize this module and all its submodules /// classes: [ PyCoolString ], /// errors: [ IOError ], /// funcs: [ do_nothing ], @@ -212,12 +213,14 @@ impl PyWrapperMut for T where T: PyWrapper + AsMut {} #[macro_export] macro_rules! create_init_submodule { ( + $(#[$meta:meta])* $(classes: [ $($class: ty),+ ],)? $(consts: [ $($const: ident),+ ],)? $(errors: [ $($error: ty),+ ],)? $(funcs: [ $($func: path),+ ],)? $(submodules: [ $($mod_name: literal: $init_submod: path),+ ],)? ) => { + $(#[$meta])* pub(crate) fn init_submodule(_name: &str, _py: $crate::pyo3::Python, m: &$crate::pyo3::types::PyModule) -> $crate::pyo3::PyResult<()> { $($( m.add_class::<$class>()?; diff --git a/src/traits.rs b/src/traits.rs index d610cc1..6febb7e 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -25,6 +25,8 @@ macro_rules! impl_compare { ($name: ident) => { #[$crate::pyo3::pymethods] impl $name { + /// Implements all the Python comparison operators in terms of the + /// Rust [`PartialOrd`](std::cmp::PartialOrd) instance. #![allow(clippy::use_self)] pub fn __richcmp__(&self, object: &Self, cmp: $crate::pyo3::basic::CompareOp) -> bool { let result = ::std::cmp::PartialOrd::partial_cmp(self, object); @@ -59,6 +61,8 @@ macro_rules! impl_hash { ($name: ident) => { #[$crate::pyo3::pymethods] impl $name { + /// Implements `__hash__` for Python in terms of the Rust + /// [`Hash`](std::hash::Hash) instance. pub fn __hash__(&self) -> i64 { let mut hasher = ::std::collections::hash_map::DefaultHasher::new(); ::std::hash::Hash::hash($crate::PyWrapper::as_inner(self), &mut hasher); @@ -73,6 +77,8 @@ macro_rules! impl_hash { #[macro_export] macro_rules! impl_repr { ($name: ident) => { + /// Implements `__repr__` for Python in terms of the Rust + /// [`Debug`](std::fmt::Debug) instance. #[$crate::pyo3::pymethods] impl $name { pub fn __repr__(&self) -> String { @@ -86,6 +92,8 @@ macro_rules! impl_repr { #[macro_export] macro_rules! impl_str { ($name: ident) => { + /// Implements `__str__` for Python in terms of the Rust + /// [`Display`](std::fmt::Display) instance. #[$crate::pyo3::pymethods] impl $name { pub fn __str__(&self) -> String { @@ -124,6 +132,8 @@ macro_rules! impl_parse { ($name: ident) => { #[$crate::pyo3::pymethods] impl $name { + /// Implements a static `parse` method for Python in terms of the + /// Rust [`FromStr`](std::str::FromStr) instance. #[staticmethod] pub fn parse(input: &str) -> $crate::pyo3::PyResult { ::from_str(input) diff --git a/src/wrappers.rs b/src/wrappers.rs index afe9ad9..454494b 100644 --- a/src/wrappers.rs +++ b/src/wrappers.rs @@ -453,6 +453,13 @@ macro_rules! py_wrap_struct { impl $name { #![allow(clippy::use_self)] + #[doc = concat!( + r"Create a new [`", + stringify!($name), + r"`] from Python arguments; corresponds to `", + $($py_class, r".",)? + r"__new__()` in Python" + )] #[new] pub fn new(py: $crate::pyo3::Python, input: $crate::pyo3::Py<$crate::pyo3::PyAny>) -> $crate::pyo3::PyResult { use $crate::pyo3::FromPyObject; @@ -579,6 +586,15 @@ macro_rules! py_wrap_union_enum { $crate::paste::paste! { #[$crate::pyo3::pymethods] impl $name { + #[doc = concat!( + r"The Python wrapper for [`", + stringify!($rs_enum), + r"::", + stringify!($variant), + r"`], creating a [`", + stringify!($name), + r"`] and taking a Python argument." + )] #[staticmethod] pub fn [< from_ $variant_name >](py: $crate::pyo3::Python, inner: $crate::private_ultimate_type!($($convert),+)) -> $crate::pyo3::PyResult { let inner = &inner; @@ -593,6 +609,10 @@ macro_rules! py_wrap_union_enum { $crate::paste::paste! { #[$crate::pyo3::pymethods] impl $name { + #[doc = concat!( + r"Create a new [`", stringify!($name), r"`] wrapping a ", + r"[`", stringify!($rs_enum), r"::", stringify!($variant), "`]." + )] #[staticmethod] pub fn [< new_ $variant_name >]() -> Self { Self::from($rs_enum::$variant) @@ -632,6 +652,13 @@ macro_rules! py_wrap_union_enum { $crate::paste::paste! { #[$crate::pyo3::pymethods] impl $name { + #[doc = concat!( + r"Create a new [`", + stringify!($name), + r"`] from a Python argument; corresponds to `", + $($py_class, r".",)? + r"__new__()` in Python" + )] #[new] pub fn new(py: $crate::pyo3::Python, input: &$crate::pyo3::PyAny) -> $crate::pyo3::PyResult { $( @@ -655,6 +682,15 @@ macro_rules! py_wrap_union_enum { )) } + #[doc = concat!( + r"Directly return the Python version of the variant discriminant wrapped by this ", + r"value; ", + r"i.e., performs the match `", + stringify!($rs_inner), + r"::Variant(x) => x` for every variant constructor in [`", + stringify!($rs_inner), + r"`]" + )] #[allow(unreachable_code, unreachable_pattern)] pub fn inner(&self, py: $crate::pyo3::Python) -> $crate::pyo3::PyResult<$crate::pyo3::Py<$crate::pyo3::PyAny>> { match &self.0 { @@ -674,15 +710,31 @@ macro_rules! py_wrap_union_enum { } $( + #[doc = concat!( + r"Tests if this [`", stringify!($name), r"`] ", + r"wraps a [`", stringify!($rs_inner), r"::", stringify!($variant_name), "`] value" + )] const fn [< is_ $variant_name >](&self) -> bool { $crate::py_wrap_union_enum!(@is_variant self, $rs_inner, $variant $(($(=> $convert)+))?) } $( + #[doc = concat!( + r"Returns `x` if this [`", stringify!($name), r"`] ", + r"wraps a `", stringify!($rs_inner), r"::", stringify!($variant_name), "`(x); ", + r"otherwise returns (Python) `None`. On the Rust side, this corresponds to ", + r"either `Some(x)` or [`None`]." + )] fn [< as_ $variant_name >](&self, py: $crate::pyo3::Python) -> Option<$crate::private_ultimate_type!($($convert),+)> { self.[< to_ $variant_name >](py).ok() } + #[doc = concat!( + r"Returns `x` if this [`", stringify!($name), r"`] ", + r"wraps a `", stringify!($rs_inner), r"::", stringify!($variant_name), "`(x); ", + r"otherwise raises a `ValueError`. On the Rust side, this corresponds to ", + r"either `Ok(x)` or `Err(...)`." + )] fn [< to_ $variant_name >](&self, py: $crate::pyo3::Python) -> $crate::pyo3::PyResult<$crate::private_ultimate_type!($($convert),+)> { if let $rs_inner::$variant(inner) = &self.0 { $crate::private_intermediate_to_python!(py, &inner $(=> $convert)+) @@ -721,7 +773,8 @@ macro_rules! py_wrap_union_enum { /// ``` #[macro_export] macro_rules! wrap_error { - ($name: ident ($inner: ty)$(;)?) => { + ($(#[$meta: meta])* $name: ident ($inner: ty)$(;)?) => { + $(#[$meta])* #[derive(Debug)] #[repr(transparent)] pub struct $name($inner); @@ -844,6 +897,10 @@ macro_rules! py_wrap_data_struct { #[rigetti_pyo3::pyo3::pymethods] impl $name { $( + #[doc = concat!( + r"Get the ", stringify!($field_name), r" field from Python. ", + r"Annotated with `@property`." + )] #[getter] fn [< get_ $field_name >](&self, py: $crate::pyo3::Python<'_>) -> $crate::pyo3::PyResult<$crate::private_ultimate_type!($($convert),+)> { use $crate::{PyWrapper, ToPython}; @@ -851,6 +908,10 @@ macro_rules! py_wrap_data_struct { $crate::private_intermediate_to_python!(py, &inner $(=> $convert)+) } + #[doc = concat!( + r"Set the ", stringify!($field_name), r" field from Python. ", + r"Annotated with `@", stringify!($field_name), r".setter`." + )] #[setter] fn [< set_ $field_name >](&mut self, py: $crate::pyo3::Python<'_>, from: $crate::private_ultimate_type!($($convert),+)) -> $crate::pyo3::PyResult<()> { use $crate::{PyTryFrom, PyWrapperMut}; diff --git a/tests/tests.rs b/tests/tests.rs new file mode 100644 index 0000000..42b8c32 --- /dev/null +++ b/tests/tests.rs @@ -0,0 +1,70 @@ +use pyo3::{types::PyModule, PyResult, Python}; + +// The code being tested is in a separate module so it can be expanded (see +// [`test_macro_expansion`]) without expanding the contents of the tests +// themselves. You can also take advantage of this when manually using `cargo +// expand`, which may be useful when testing or debugging the macros defined in +// this crate. This file must be in a subdirectory (`wrapper_tests/mod.rs` +// instead of `wrapper_tests.rs`) because the generated `.expanded.rs` file +// cannot be in the root `tests/` directory or `cargo test` will attempt to +// build it as a test case as well. +mod wrapper_tests; + +#[test] +fn test_enum_as_data_struct_member() { + wrapper_tests::append_to_inittab(); + pyo3::prepare_freethreaded_python(); + let result: PyResult<()> = Python::with_gil(|py| { + let code = r#" +from wrapper_tests import TestEnumUnaliased, TestEnumAliased, TestStruct, TestUnionEnum + +struct = TestStruct() + +assert struct.test_enum_unaliased == TestEnumUnaliased.One +assert struct.test_enum_aliased == TestEnumAliased.NONE + +struct.test_enum_unaliased = TestEnumUnaliased.Two +struct.test_enum_aliased = TestEnumAliased.Two + +assert struct.test_enum_unaliased == TestEnumUnaliased.Two +assert struct.test_enum_aliased == TestEnumAliased.Two + +assert TestUnionEnum.new_unit().is_unit() +"#; + PyModule::from_code(py, code, "example.py", "example")?; + + Ok(()) + }); + + result.expect("python code should execute without issue") +} + +#[test] +fn test_macro_expansion() { + // To regenerate the snapshot, run this test with the environment variable + // `MACROTEST=overwrite`, or alternatively delete the generated + // `tests/wrapper_tests/mod.expanded.rs` file and rerun this test. + macrotest::expand_args( + "tests/wrapper_tests/mod.rs", + // We have to specify a specific OS target because until PyO3 v0.22, + // PyO3 transitively depends on the + // [rust-ctor](https://crates.io/crates/ctor) crate, which generates + // different output on different OSes. Once we're doing *that*, we have + // to specify a specific Python ABI so that PyO3 doesn't get alarmed + // about cross-compilation. We pick the oldest availble option so that + // we can be flexible with which Python interpreter is available on the + // system. This is all a minor headache. + // + // In particular, this means that if you are running these tests on a + // different OS, you will need to install the specified target. The + // target is specifically chosen to be the one we use on CI, so CI does + // not need an extra `rustup target add`, but some developers will. + &[ + "--target", + "x86_64-unknown-linux-gnu", + "--no-default-features", + "--features", + "pyo3/abi3-py37", + ], + ) +} diff --git a/tests/wrapper_tests/mod.expanded.rs b/tests/wrapper_tests/mod.expanded.rs new file mode 100644 index 0000000..5ab2f05 --- /dev/null +++ b/tests/wrapper_tests/mod.expanded.rs @@ -0,0 +1,2430 @@ +use pyo3::{self, pymodule, types::PyModule, PyResult, Python}; +pub mod rust { + pub enum TestEnum { + One, + Two, + } + #[automatically_derived] + impl ::core::clone::Clone for TestEnum { + #[inline] + fn clone(&self) -> TestEnum { + *self + } + } + #[automatically_derived] + impl ::core::marker::Copy for TestEnum {} + pub enum TestUnionEnum { + Unit, + String(String), + } + #[automatically_derived] + impl ::core::clone::Clone for TestUnionEnum { + #[inline] + fn clone(&self) -> TestUnionEnum { + match self { + TestUnionEnum::Unit => TestUnionEnum::Unit, + TestUnionEnum::String(__self_0) => { + TestUnionEnum::String(::core::clone::Clone::clone(__self_0)) + } + } + } + } + pub struct TestStruct { + pub test_enum_unaliased: TestEnum, + pub test_enum_aliased: TestEnum, + } + #[automatically_derived] + impl ::core::clone::Clone for TestStruct { + #[inline] + fn clone(&self) -> TestStruct { + let _: ::core::clone::AssertParamIsClone; + *self + } + } + #[automatically_derived] + impl ::core::marker::Copy for TestStruct {} +} +pub mod python { + use super::rust::*; + use pyo3::pymethods; + use rigetti_pyo3::{ + create_init_submodule, py_wrap_data_struct, py_wrap_simple_enum, + py_wrap_union_enum, + }; + pub(crate) fn init_submodule( + _name: &str, + _py: ::rigetti_pyo3::pyo3::Python, + m: &::rigetti_pyo3::pyo3::types::PyModule, + ) -> ::rigetti_pyo3::pyo3::PyResult<()> { + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + Ok(()) + } + #[repr(transparent)] + #[allow(clippy::use_self)] + pub struct PyTestUnionEnum(TestUnionEnum); + #[automatically_derived] + #[allow(clippy::use_self)] + impl ::core::clone::Clone for PyTestUnionEnum { + #[inline] + fn clone(&self) -> PyTestUnionEnum { + PyTestUnionEnum(::core::clone::Clone::clone(&self.0)) + } + } + const _: () = { + use ::pyo3 as _pyo3; + unsafe impl _pyo3::type_object::PyTypeInfo for PyTestUnionEnum { + type AsRefTarget = _pyo3::PyCell; + const NAME: &'static str = "TestUnionEnum"; + const MODULE: ::std::option::Option<&'static str> = ::core::option::Option::None; + #[inline] + fn type_object_raw(py: _pyo3::Python<'_>) -> *mut _pyo3::ffi::PyTypeObject { + ::lazy_type_object() + .get_or_init(py) + .as_type_ptr() + } + } + impl _pyo3::PyClass for PyTestUnionEnum { + type Frozen = _pyo3::pyclass::boolean_struct::False; + } + impl<'a, 'py> _pyo3::impl_::extract_argument::PyFunctionArgument<'a, 'py> + for &'a PyTestUnionEnum { + type Holder = ::std::option::Option<_pyo3::PyRef<'py, PyTestUnionEnum>>; + #[inline] + fn extract( + obj: &'py _pyo3::PyAny, + holder: &'a mut Self::Holder, + ) -> _pyo3::PyResult { + _pyo3::impl_::extract_argument::extract_pyclass_ref(obj, holder) + } + } + impl<'a, 'py> _pyo3::impl_::extract_argument::PyFunctionArgument<'a, 'py> + for &'a mut PyTestUnionEnum { + type Holder = ::std::option::Option<_pyo3::PyRefMut<'py, PyTestUnionEnum>>; + #[inline] + fn extract( + obj: &'py _pyo3::PyAny, + holder: &'a mut Self::Holder, + ) -> _pyo3::PyResult { + _pyo3::impl_::extract_argument::extract_pyclass_ref_mut(obj, holder) + } + } + impl _pyo3::IntoPy<_pyo3::PyObject> for PyTestUnionEnum { + fn into_py(self, py: _pyo3::Python) -> _pyo3::PyObject { + _pyo3::IntoPy::into_py(_pyo3::Py::new(py, self).unwrap(), py) + } + } + impl _pyo3::impl_::pyclass::PyClassImpl for PyTestUnionEnum { + const IS_BASETYPE: bool = false; + const IS_SUBCLASS: bool = false; + const IS_MAPPING: bool = false; + const IS_SEQUENCE: bool = false; + type BaseType = _pyo3::PyAny; + type ThreadChecker = _pyo3::impl_::pyclass::SendablePyClass; + type Inventory = Pyo3MethodsInventoryForPyTestUnionEnum; + type PyClassMutability = <<_pyo3::PyAny as _pyo3::impl_::pyclass::PyClassBaseType>::PyClassMutability as _pyo3::impl_::pycell::PyClassMutability>::MutableChild; + type Dict = _pyo3::impl_::pyclass::PyClassDummySlot; + type WeakRef = _pyo3::impl_::pyclass::PyClassDummySlot; + type BaseNativeType = _pyo3::PyAny; + fn items_iter() -> _pyo3::impl_::pyclass::PyClassItemsIter { + use _pyo3::impl_::pyclass::*; + let collector = PyClassImplCollector::::new(); + static INTRINSIC_ITEMS: PyClassItems = PyClassItems { + methods: &[], + slots: &[], + }; + PyClassItemsIter::new( + &INTRINSIC_ITEMS, + ::std::boxed::Box::new( + ::std::iter::Iterator::map( + _pyo3::inventory::iter::< + ::Inventory, + >(), + _pyo3::impl_::pyclass::PyClassInventory::items, + ), + ), + ) + } + fn doc(py: _pyo3::Python<'_>) -> _pyo3::PyResult<&'static ::std::ffi::CStr> { + use _pyo3::impl_::pyclass::*; + static DOC: _pyo3::once_cell::GILOnceCell< + ::std::borrow::Cow<'static, ::std::ffi::CStr>, + > = _pyo3::once_cell::GILOnceCell::new(); + DOC.get_or_try_init( + py, + || { + let collector = PyClassImplCollector::::new(); + build_pyclass_doc( + ::NAME, + "\0", + ::std::option::Option::None + .or_else(|| collector.new_text_signature()), + ) + }, + ) + .map(::std::ops::Deref::deref) + } + fn lazy_type_object() -> &'static _pyo3::impl_::pyclass::LazyTypeObject< + Self, + > { + use _pyo3::impl_::pyclass::LazyTypeObject; + static TYPE_OBJECT: LazyTypeObject = LazyTypeObject::new(); + &TYPE_OBJECT + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + impl PyTestUnionEnum {} + #[doc(hidden)] + pub struct Pyo3MethodsInventoryForPyTestUnionEnum { + items: _pyo3::impl_::pyclass::PyClassItems, + } + impl Pyo3MethodsInventoryForPyTestUnionEnum { + pub const fn new(items: _pyo3::impl_::pyclass::PyClassItems) -> Self { + Self { items } + } + } + impl _pyo3::impl_::pyclass::PyClassInventory + for Pyo3MethodsInventoryForPyTestUnionEnum { + fn items(&self) -> &_pyo3::impl_::pyclass::PyClassItems { + &self.items + } + } + impl ::inventory::Collect for Pyo3MethodsInventoryForPyTestUnionEnum { + #[inline] + fn registry() -> &'static ::inventory::Registry { + static REGISTRY: ::inventory::Registry = ::inventory::Registry::new(); + ®ISTRY + } + } + }; + impl ::rigetti_pyo3::PyTryFrom for TestUnionEnum { + fn py_try_from( + py: ::rigetti_pyo3::pyo3::Python, + item: &PyTestUnionEnum, + ) -> ::rigetti_pyo3::pyo3::PyResult { + Ok(item.0.clone()) + } + } + impl ::rigetti_pyo3::PyTryFrom<::rigetti_pyo3::pyo3::PyAny> for PyTestUnionEnum { + fn py_try_from( + py: ::rigetti_pyo3::pyo3::Python, + item: &::rigetti_pyo3::pyo3::PyAny, + ) -> ::rigetti_pyo3::pyo3::PyResult { + item.extract() + } + } + impl ::rigetti_pyo3::PyTryFrom for PyTestUnionEnum { + fn py_try_from( + py: ::rigetti_pyo3::pyo3::Python, + item: &PyTestUnionEnum, + ) -> ::rigetti_pyo3::pyo3::PyResult { + Ok(item.clone()) + } + } + #[allow(clippy::use_self)] + impl ::rigetti_pyo3::ToPython for TestUnionEnum { + fn to_python( + &self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult { + { Ok(PyTestUnionEnum::from(self.clone())) } + } + } + #[allow(clippy::use_self)] + impl<'a> ::rigetti_pyo3::ToPython for &'a TestUnionEnum { + fn to_python( + &self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult { + { + >::to_python(*self, py) + } + } + } + #[allow(clippy::use_self)] + impl ::rigetti_pyo3::ToPython<::rigetti_pyo3::pyo3::Py<::rigetti_pyo3::pyo3::PyAny>> + for PyTestUnionEnum { + fn to_python( + &self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult< + ::rigetti_pyo3::pyo3::Py<::rigetti_pyo3::pyo3::PyAny>, + > { + { Ok(::to_object(self, py)) } + } + } + #[allow(clippy::use_self)] + impl< + 'a, + > ::rigetti_pyo3::ToPython<::rigetti_pyo3::pyo3::Py<::rigetti_pyo3::pyo3::PyAny>> + for &'a PyTestUnionEnum { + fn to_python( + &self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult< + ::rigetti_pyo3::pyo3::Py<::rigetti_pyo3::pyo3::PyAny>, + > { + { + , + >>::to_python(*self, py) + } + } + } + impl From for TestUnionEnum { + fn from(wrapper: PyTestUnionEnum) -> Self { + wrapper.0 + } + } + impl From for PyTestUnionEnum { + fn from(inner: TestUnionEnum) -> Self { + Self(inner) + } + } + impl From<&TestUnionEnum> for PyTestUnionEnum { + fn from(inner: &TestUnionEnum) -> Self { + Self(inner.clone()) + } + } + impl AsRef for PyTestUnionEnum { + fn as_ref(&self) -> &TestUnionEnum { + &self.0 + } + } + impl ::rigetti_pyo3::PyWrapper for PyTestUnionEnum { + type Inner = TestUnionEnum; + } + impl ::rigetti_pyo3::pyo3::conversion::ToPyObject for PyTestUnionEnum { + fn to_object( + &self, + py: ::rigetti_pyo3::pyo3::Python, + ) -> ::rigetti_pyo3::pyo3::PyObject { + #[allow(clippy::use_self)] + const NAME: &'static str = "PyTestUnionEnum"; + let cell = ::rigetti_pyo3::pyo3::PyCell::new(py, self.clone()) + .unwrap_or_else(|err| { + { + ::core::panicking::panic_fmt( + format_args!( + "failed to create {0} on Python heap: {1}", NAME, err, + ), + ); + } + }); + ::rigetti_pyo3::pyo3::conversion::ToPyObject::to_object(&cell, py) + } + } + impl AsMut<::Inner> + for PyTestUnionEnum { + fn as_mut( + &mut self, + ) -> &mut ::Inner { + &mut self.0 + } + } + impl PyTestUnionEnum { + ///Create a new [`PyTestUnionEnum`] wrapping a [`TestUnionEnum::Unit`]. + pub fn new_unit() -> Self { + Self::from(TestUnionEnum::Unit) + } + } + const _: () = { + use ::pyo3 as _pyo3; + #[allow(non_upper_case_globals)] + const _: () = { + static __INVENTORY: ::inventory::Node = ::inventory::Node { + value: &{ + type Inventory = ::Inventory; + Inventory::new(_pyo3::impl_::pyclass::PyClassItems { + methods: &[ + _pyo3::class::PyMethodDefType::Static( + _pyo3::impl_::pymethods::PyMethodDef::noargs( + "new_unit\0", + _pyo3::impl_::pymethods::PyCFunction({ + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + _args: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::noargs( + _slf, + _args, + PyTestUnionEnum::__pymethod_new_unit__, + ) + } + trampoline + }), + "new_unit()\n--\n\nCreate a new [`PyTestUnionEnum`] wrapping a [`TestUnionEnum::Unit`].\u{0}", + ) + .flags(_pyo3::ffi::METH_STATIC), + ), + ], + slots: &[], + }) + }, + next: ::inventory::core::cell::UnsafeCell::new( + ::inventory::core::option::Option::None, + ), + }; + #[link_section = ".text.startup"] + unsafe extern "C" fn __ctor() { + unsafe { + ::inventory::ErasedNode::submit(__INVENTORY.value, &__INVENTORY) + } + } + #[used] + #[link_section = ".init_array"] + static __CTOR: unsafe extern "C" fn() = __ctor; + }; + #[doc(hidden)] + #[allow(non_snake_case)] + impl PyTestUnionEnum { + unsafe fn __pymethod_new_unit__<'py>( + py: _pyo3::Python<'py>, + _slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestUnionEnum::new_unit; + _pyo3::impl_::wrap::OkWrap::wrap(function(), py) + .map_err(::core::convert::Into::<_pyo3::PyErr>::into) + .map(_pyo3::PyObject::into_ptr) + } + } + }; + impl PyTestUnionEnum { + ///The Python wrapper for [`TestUnionEnum::String`], creating a [`PyTestUnionEnum`] and taking a Python argument. + pub fn from_string( + py: ::rigetti_pyo3::pyo3::Python, + inner: String, + ) -> ::rigetti_pyo3::pyo3::PyResult { + let inner = &inner; + { <_ as ::rigetti_pyo3::PyTryFrom>::py_try_from(py, inner) } + .map(TestUnionEnum::String) + .map(Self) + } + } + const _: () = { + use ::pyo3 as _pyo3; + #[allow(non_upper_case_globals)] + const _: () = { + static __INVENTORY: ::inventory::Node = ::inventory::Node { + value: &{ + type Inventory = ::Inventory; + Inventory::new(_pyo3::impl_::pyclass::PyClassItems { + methods: &[ + _pyo3::class::PyMethodDefType::Static( + _pyo3::impl_::pymethods::PyMethodDef::cfunction_with_keywords( + "from_string\0", + _pyo3::impl_::pymethods::PyCFunctionWithKeywords({ + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + _args: *mut _pyo3::ffi::PyObject, + _kwargs: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::cfunction_with_keywords( + _slf, + _args, + _kwargs, + PyTestUnionEnum::__pymethod_from_string__, + ) + } + trampoline + }), + "from_string(inner)\n--\n\nThe Python wrapper for [`TestUnionEnum::String`], creating a [`PyTestUnionEnum`] and taking a Python argument.\u{0}", + ) + .flags(_pyo3::ffi::METH_STATIC), + ), + ], + slots: &[], + }) + }, + next: ::inventory::core::cell::UnsafeCell::new( + ::inventory::core::option::Option::None, + ), + }; + #[link_section = ".text.startup"] + unsafe extern "C" fn __ctor() { + unsafe { + ::inventory::ErasedNode::submit(__INVENTORY.value, &__INVENTORY) + } + } + #[used] + #[link_section = ".init_array"] + static __CTOR: unsafe extern "C" fn() = __ctor; + }; + #[doc(hidden)] + #[allow(non_snake_case)] + impl PyTestUnionEnum { + unsafe fn __pymethod_from_string__<'py>( + py: _pyo3::Python<'py>, + _slf: *mut _pyo3::ffi::PyObject, + _args: *mut _pyo3::ffi::PyObject, + _kwargs: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestUnionEnum::from_string; + const DESCRIPTION: _pyo3::impl_::extract_argument::FunctionDescription = _pyo3::impl_::extract_argument::FunctionDescription { + cls_name: ::std::option::Option::Some( + ::NAME, + ), + func_name: "from_string", + positional_parameter_names: &["inner"], + positional_only_parameters: 0usize, + required_positional_parameters: 1usize, + keyword_only_parameters: &[], + }; + let mut output = [::std::option::Option::None; 1usize]; + let (_args, _kwargs) = DESCRIPTION + .extract_arguments_tuple_dict::< + _pyo3::impl_::extract_argument::NoVarargs, + _pyo3::impl_::extract_argument::NoVarkeywords, + >(py, _args, _kwargs, &mut output)?; + _pyo3::impl_::wrap::OkWrap::wrap( + function( + py, + _pyo3::impl_::extract_argument::extract_argument( + _pyo3::impl_::extract_argument::unwrap_required_argument( + output[0usize], + ), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + "inner", + )?, + ), + py, + ) + .map_err(::core::convert::Into::<_pyo3::PyErr>::into) + .map(_pyo3::PyObject::into_ptr) + } + } + }; + impl PyTestUnionEnum { + ///Create a new [`PyTestUnionEnum`] from a Python argument; corresponds to `TestUnionEnum.__new__()` in Python + pub fn new( + py: ::rigetti_pyo3::pyo3::Python, + input: &::rigetti_pyo3::pyo3::PyAny, + ) -> ::rigetti_pyo3::pyo3::PyResult { + if let Ok(inner) = <_ as ::rigetti_pyo3::PyTryFrom< + ::rigetti_pyo3::pyo3::PyAny, + >>::py_try_from(py, input) { + let inner = &inner; + let converted = { + <_ as ::rigetti_pyo3::PyTryFrom>::py_try_from(py, inner) + }; + if let Ok(item) = converted { + return Ok(Self::from(TestUnionEnum::String(item))); + } + } + Err( + ::rigetti_pyo3::pyo3::exceptions::PyValueError::new_err({ + let res = ::alloc::fmt::format( + format_args!( + "could not create {0} from {1}", "PyTestUnionEnum", input + .repr() ?, + ), + ); + res + }), + ) + } + ///Directly return the Python version of the variant discriminant wrapped by this value; i.e., performs the match `TestUnionEnum::Variant(x) => x` for every variant constructor in [`TestUnionEnum`] + #[allow(unreachable_code, unreachable_pattern)] + pub fn inner( + &self, + py: ::rigetti_pyo3::pyo3::Python, + ) -> ::rigetti_pyo3::pyo3::PyResult< + ::rigetti_pyo3::pyo3::Py<::rigetti_pyo3::pyo3::PyAny>, + > { + match &self.0 { + TestUnionEnum::String(inner) => { + Ok( + ::rigetti_pyo3::pyo3::conversion::IntoPy::< + ::rigetti_pyo3::pyo3::Py<::rigetti_pyo3::pyo3::PyAny>, + >::into_py( + { + let inner: String = ::rigetti_pyo3::ToPython::< + String, + >::to_python(&inner, py)?; + Ok::<_, ::rigetti_pyo3::pyo3::PyErr>(inner) + }?, + py, + ), + ) + } + _ => { + use ::rigetti_pyo3::pyo3::exceptions::PyRuntimeError; + Err( + PyRuntimeError::new_err( + "Enum variant has no inner data or is unimplemented", + ), + ) + } + } + } + ///Tests if this [`PyTestUnionEnum`] wraps a [`TestUnionEnum::unit`] value + const fn is_unit(&self) -> bool { + match &self.0 { + TestUnionEnum::Unit => true, + _ => false, + } + } + ///Tests if this [`PyTestUnionEnum`] wraps a [`TestUnionEnum::string`] value + const fn is_string(&self) -> bool { + match &self.0 { + TestUnionEnum::String(_) => true, + _ => false, + } + } + ///Returns `x` if this [`PyTestUnionEnum`] wraps a `TestUnionEnum::string`(x); otherwise returns (Python) `None`. On the Rust side, this corresponds to either `Some(x)` or [`None`]. + fn as_string(&self, py: ::rigetti_pyo3::pyo3::Python) -> Option { + self.to_string(py).ok() + } + ///Returns `x` if this [`PyTestUnionEnum`] wraps a `TestUnionEnum::string`(x); otherwise raises a `ValueError`. On the Rust side, this corresponds to either `Ok(x)` or `Err(...)`. + fn to_string( + &self, + py: ::rigetti_pyo3::pyo3::Python, + ) -> ::rigetti_pyo3::pyo3::PyResult { + if let TestUnionEnum::String(inner) = &self.0 { + { + let inner: String = ::rigetti_pyo3::ToPython::< + String, + >::to_python(&inner, py)?; + Ok::<_, ::rigetti_pyo3::pyo3::PyErr>(inner) + } + } else { + Err( + ::rigetti_pyo3::pyo3::exceptions::PyValueError::new_err( + "expected self to be a string", + ), + ) + } + } + } + const _: () = { + use ::pyo3 as _pyo3; + #[allow(non_upper_case_globals)] + const _: () = { + static __INVENTORY: ::inventory::Node = ::inventory::Node { + value: &{ + type Inventory = ::Inventory; + Inventory::new(_pyo3::impl_::pyclass::PyClassItems { + methods: &[ + _pyo3::class::PyMethodDefType::Method( + _pyo3::impl_::pymethods::PyMethodDef::noargs( + "inner\0", + _pyo3::impl_::pymethods::PyCFunction({ + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + _args: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::noargs( + _slf, + _args, + PyTestUnionEnum::__pymethod_inner__, + ) + } + trampoline + }), + "inner($self)\n--\n\nDirectly return the Python version of the variant discriminant wrapped by this value; i.e., performs the match `TestUnionEnum::Variant(x) => x` for every variant constructor in [`TestUnionEnum`]\u{0}", + ), + ), + _pyo3::class::PyMethodDefType::Method( + _pyo3::impl_::pymethods::PyMethodDef::noargs( + "is_unit\0", + _pyo3::impl_::pymethods::PyCFunction({ + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + _args: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::noargs( + _slf, + _args, + PyTestUnionEnum::__pymethod_is_unit__, + ) + } + trampoline + }), + "is_unit($self)\n--\n\nTests if this [`PyTestUnionEnum`] wraps a [`TestUnionEnum::unit`] value\u{0}", + ), + ), + _pyo3::class::PyMethodDefType::Method( + _pyo3::impl_::pymethods::PyMethodDef::noargs( + "is_string\0", + _pyo3::impl_::pymethods::PyCFunction({ + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + _args: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::noargs( + _slf, + _args, + PyTestUnionEnum::__pymethod_is_string__, + ) + } + trampoline + }), + "is_string($self)\n--\n\nTests if this [`PyTestUnionEnum`] wraps a [`TestUnionEnum::string`] value\u{0}", + ), + ), + _pyo3::class::PyMethodDefType::Method( + _pyo3::impl_::pymethods::PyMethodDef::noargs( + "as_string\0", + _pyo3::impl_::pymethods::PyCFunction({ + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + _args: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::noargs( + _slf, + _args, + PyTestUnionEnum::__pymethod_as_string__, + ) + } + trampoline + }), + "as_string($self)\n--\n\nReturns `x` if this [`PyTestUnionEnum`] wraps a `TestUnionEnum::string`(x); otherwise returns (Python) `None`. On the Rust side, this corresponds to either `Some(x)` or [`None`].\u{0}", + ), + ), + _pyo3::class::PyMethodDefType::Method( + _pyo3::impl_::pymethods::PyMethodDef::noargs( + "to_string\0", + _pyo3::impl_::pymethods::PyCFunction({ + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + _args: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::noargs( + _slf, + _args, + PyTestUnionEnum::__pymethod_to_string__, + ) + } + trampoline + }), + "to_string($self)\n--\n\nReturns `x` if this [`PyTestUnionEnum`] wraps a `TestUnionEnum::string`(x); otherwise raises a `ValueError`. On the Rust side, this corresponds to either `Ok(x)` or `Err(...)`.\u{0}", + ), + ), + ], + slots: &[ + _pyo3::ffi::PyType_Slot { + slot: _pyo3::ffi::Py_tp_new, + pfunc: { + unsafe extern "C" fn trampoline( + subtype: *mut _pyo3::ffi::PyTypeObject, + args: *mut _pyo3::ffi::PyObject, + kwargs: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + use _pyo3::impl_::pyclass::*; + impl PyClassNewTextSignature + for PyClassImplCollector { + #[inline] + fn new_text_signature( + self, + ) -> ::std::option::Option<&'static str> { + ::std::option::Option::Some("(input)") + } + } + _pyo3::impl_::trampoline::newfunc( + subtype, + args, + kwargs, + PyTestUnionEnum::__pymethod___new____, + ) + } + trampoline + } as _pyo3::ffi::newfunc as _, + }, + ], + }) + }, + next: ::inventory::core::cell::UnsafeCell::new( + ::inventory::core::option::Option::None, + ), + }; + #[link_section = ".text.startup"] + unsafe extern "C" fn __ctor() { + unsafe { + ::inventory::ErasedNode::submit(__INVENTORY.value, &__INVENTORY) + } + } + #[used] + #[link_section = ".init_array"] + static __CTOR: unsafe extern "C" fn() = __ctor; + }; + #[doc(hidden)] + #[allow(non_snake_case)] + impl PyTestUnionEnum { + unsafe fn __pymethod___new____( + py: _pyo3::Python<'_>, + _slf: *mut _pyo3::ffi::PyTypeObject, + _args: *mut _pyo3::ffi::PyObject, + _kwargs: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + use _pyo3::callback::IntoPyCallbackOutput; + let function = PyTestUnionEnum::new; + const DESCRIPTION: _pyo3::impl_::extract_argument::FunctionDescription = _pyo3::impl_::extract_argument::FunctionDescription { + cls_name: ::std::option::Option::Some( + ::NAME, + ), + func_name: "__new__", + positional_parameter_names: &["input"], + positional_only_parameters: 0usize, + required_positional_parameters: 1usize, + keyword_only_parameters: &[], + }; + let mut output = [::std::option::Option::None; 1usize]; + let (_args, _kwargs) = DESCRIPTION + .extract_arguments_tuple_dict::< + _pyo3::impl_::extract_argument::NoVarargs, + _pyo3::impl_::extract_argument::NoVarkeywords, + >(py, _args, _kwargs, &mut output)?; + let result = PyTestUnionEnum::new( + py, + _pyo3::impl_::extract_argument::extract_argument( + _pyo3::impl_::extract_argument::unwrap_required_argument( + output[0usize], + ), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + "input", + )?, + ); + let initializer: _pyo3::PyClassInitializer = result + .convert(py)?; + let cell = initializer.create_cell_from_subtype(py, _slf)?; + ::std::result::Result::Ok(cell as *mut _pyo3::ffi::PyObject) + } + unsafe fn __pymethod_inner__<'py>( + py: _pyo3::Python<'py>, + _slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestUnionEnum::inner; + _pyo3::impl_::wrap::OkWrap::wrap( + function( + _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestUnionEnum, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + py, + ), + py, + ) + .map_err(::core::convert::Into::<_pyo3::PyErr>::into) + .map(_pyo3::PyObject::into_ptr) + } + unsafe fn __pymethod_is_unit__<'py>( + py: _pyo3::Python<'py>, + _slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestUnionEnum::is_unit; + _pyo3::impl_::wrap::OkWrap::wrap( + function( + _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestUnionEnum, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + ), + py, + ) + .map_err(::core::convert::Into::<_pyo3::PyErr>::into) + .map(_pyo3::PyObject::into_ptr) + } + unsafe fn __pymethod_is_string__<'py>( + py: _pyo3::Python<'py>, + _slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestUnionEnum::is_string; + _pyo3::impl_::wrap::OkWrap::wrap( + function( + _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestUnionEnum, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + ), + py, + ) + .map_err(::core::convert::Into::<_pyo3::PyErr>::into) + .map(_pyo3::PyObject::into_ptr) + } + unsafe fn __pymethod_as_string__<'py>( + py: _pyo3::Python<'py>, + _slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestUnionEnum::as_string; + _pyo3::impl_::wrap::OkWrap::wrap( + function( + _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestUnionEnum, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + py, + ), + py, + ) + .map_err(::core::convert::Into::<_pyo3::PyErr>::into) + .map(_pyo3::PyObject::into_ptr) + } + unsafe fn __pymethod_to_string__<'py>( + py: _pyo3::Python<'py>, + _slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestUnionEnum::to_string; + _pyo3::impl_::wrap::OkWrap::wrap( + function( + _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestUnionEnum, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + py, + ), + py, + ) + .map_err(::core::convert::Into::<_pyo3::PyErr>::into) + .map(_pyo3::PyObject::into_ptr) + } + } + }; + pub enum PyTestEnumUnaliased { + One, + Two, + } + const _: () = { + use ::pyo3 as _pyo3; + unsafe impl _pyo3::type_object::PyTypeInfo for PyTestEnumUnaliased { + type AsRefTarget = _pyo3::PyCell; + const NAME: &'static str = "TestEnumUnaliased"; + const MODULE: ::std::option::Option<&'static str> = ::core::option::Option::None; + #[inline] + fn type_object_raw(py: _pyo3::Python<'_>) -> *mut _pyo3::ffi::PyTypeObject { + ::lazy_type_object() + .get_or_init(py) + .as_type_ptr() + } + } + impl _pyo3::PyClass for PyTestEnumUnaliased { + type Frozen = _pyo3::pyclass::boolean_struct::False; + } + impl<'a, 'py> _pyo3::impl_::extract_argument::PyFunctionArgument<'a, 'py> + for &'a PyTestEnumUnaliased { + type Holder = ::std::option::Option<_pyo3::PyRef<'py, PyTestEnumUnaliased>>; + #[inline] + fn extract( + obj: &'py _pyo3::PyAny, + holder: &'a mut Self::Holder, + ) -> _pyo3::PyResult { + _pyo3::impl_::extract_argument::extract_pyclass_ref(obj, holder) + } + } + impl<'a, 'py> _pyo3::impl_::extract_argument::PyFunctionArgument<'a, 'py> + for &'a mut PyTestEnumUnaliased { + type Holder = ::std::option::Option< + _pyo3::PyRefMut<'py, PyTestEnumUnaliased>, + >; + #[inline] + fn extract( + obj: &'py _pyo3::PyAny, + holder: &'a mut Self::Holder, + ) -> _pyo3::PyResult { + _pyo3::impl_::extract_argument::extract_pyclass_ref_mut(obj, holder) + } + } + impl _pyo3::IntoPy<_pyo3::PyObject> for PyTestEnumUnaliased { + fn into_py(self, py: _pyo3::Python) -> _pyo3::PyObject { + _pyo3::IntoPy::into_py(_pyo3::Py::new(py, self).unwrap(), py) + } + } + impl _pyo3::impl_::pyclass::PyClassImpl for PyTestEnumUnaliased { + const IS_BASETYPE: bool = false; + const IS_SUBCLASS: bool = false; + const IS_MAPPING: bool = false; + const IS_SEQUENCE: bool = false; + type BaseType = _pyo3::PyAny; + type ThreadChecker = _pyo3::impl_::pyclass::SendablePyClass< + PyTestEnumUnaliased, + >; + type Inventory = Pyo3MethodsInventoryForPyTestEnumUnaliased; + type PyClassMutability = <<_pyo3::PyAny as _pyo3::impl_::pyclass::PyClassBaseType>::PyClassMutability as _pyo3::impl_::pycell::PyClassMutability>::MutableChild; + type Dict = _pyo3::impl_::pyclass::PyClassDummySlot; + type WeakRef = _pyo3::impl_::pyclass::PyClassDummySlot; + type BaseNativeType = _pyo3::PyAny; + fn items_iter() -> _pyo3::impl_::pyclass::PyClassItemsIter { + use _pyo3::impl_::pyclass::*; + let collector = PyClassImplCollector::::new(); + static INTRINSIC_ITEMS: PyClassItems = PyClassItems { + methods: &[ + _pyo3::class::PyMethodDefType::ClassAttribute({ + _pyo3::class::PyClassAttributeDef::new( + { "One\0" }, + _pyo3::impl_::pymethods::PyClassAttributeFactory( + PyTestEnumUnaliased::__pymethod_One__, + ), + ) + }), + _pyo3::class::PyMethodDefType::ClassAttribute({ + _pyo3::class::PyClassAttributeDef::new( + { "Two\0" }, + _pyo3::impl_::pymethods::PyClassAttributeFactory( + PyTestEnumUnaliased::__pymethod_Two__, + ), + ) + }), + ], + slots: &[ + { + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::reprfunc( + _slf, + PyTestEnumUnaliased::__pymethod___default___pyo3__repr______, + ) + } + _pyo3::ffi::PyType_Slot { + slot: _pyo3::ffi::Py_tp_repr, + pfunc: trampoline as _pyo3::ffi::reprfunc as _, + } + }, + { + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::unaryfunc( + _slf, + PyTestEnumUnaliased::__pymethod___default___pyo3__int______, + ) + } + _pyo3::ffi::PyType_Slot { + slot: _pyo3::ffi::Py_nb_int, + pfunc: trampoline as _pyo3::ffi::unaryfunc as _, + } + }, + { + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + arg0: *mut _pyo3::ffi::PyObject, + arg1: ::std::os::raw::c_int, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::richcmpfunc( + _slf, + arg0, + arg1, + PyTestEnumUnaliased::__pymethod___default___pyo3__richcmp______, + ) + } + _pyo3::ffi::PyType_Slot { + slot: _pyo3::ffi::Py_tp_richcompare, + pfunc: trampoline as _pyo3::ffi::richcmpfunc as _, + } + }, + ], + }; + PyClassItemsIter::new( + &INTRINSIC_ITEMS, + ::std::boxed::Box::new( + ::std::iter::Iterator::map( + _pyo3::inventory::iter::< + ::Inventory, + >(), + _pyo3::impl_::pyclass::PyClassInventory::items, + ), + ), + ) + } + fn doc(py: _pyo3::Python<'_>) -> _pyo3::PyResult<&'static ::std::ffi::CStr> { + use _pyo3::impl_::pyclass::*; + static DOC: _pyo3::once_cell::GILOnceCell< + ::std::borrow::Cow<'static, ::std::ffi::CStr>, + > = _pyo3::once_cell::GILOnceCell::new(); + DOC.get_or_try_init( + py, + || { + let collector = PyClassImplCollector::::new(); + build_pyclass_doc( + ::NAME, + "\0", + ::std::option::Option::None + .or_else(|| collector.new_text_signature()), + ) + }, + ) + .map(::std::ops::Deref::deref) + } + fn lazy_type_object() -> &'static _pyo3::impl_::pyclass::LazyTypeObject< + Self, + > { + use _pyo3::impl_::pyclass::LazyTypeObject; + static TYPE_OBJECT: LazyTypeObject = LazyTypeObject::new(); + &TYPE_OBJECT + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + impl PyTestEnumUnaliased { + fn __pymethod_One__( + py: _pyo3::Python<'_>, + ) -> _pyo3::PyResult<_pyo3::PyObject> { + ::std::result::Result::Ok( + _pyo3::IntoPy::into_py(PyTestEnumUnaliased::One, py), + ) + } + fn __pymethod_Two__( + py: _pyo3::Python<'_>, + ) -> _pyo3::PyResult<_pyo3::PyObject> { + ::std::result::Result::Ok( + _pyo3::IntoPy::into_py(PyTestEnumUnaliased::Two, py), + ) + } + unsafe fn __pymethod___default___pyo3__repr______( + py: _pyo3::Python<'_>, + _raw_slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestEnumUnaliased::__pyo3__repr__; + let _slf = _raw_slf; + _pyo3::callback::convert( + py, + PyTestEnumUnaliased::__pyo3__repr__( + _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestEnumUnaliased, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + ), + ) + } + unsafe fn __pymethod___default___pyo3__int______( + py: _pyo3::Python<'_>, + _raw_slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestEnumUnaliased::__pyo3__int__; + let _slf = _raw_slf; + _pyo3::callback::convert( + py, + PyTestEnumUnaliased::__pyo3__int__( + _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestEnumUnaliased, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + ), + ) + } + unsafe fn __pymethod___default___pyo3__richcmp______( + py: _pyo3::Python<'_>, + _raw_slf: *mut _pyo3::ffi::PyObject, + arg0: *mut _pyo3::ffi::PyObject, + arg1: ::std::os::raw::c_int, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestEnumUnaliased::__pyo3__richcmp__; + let _slf = _raw_slf; + _pyo3::callback::convert( + py, + PyTestEnumUnaliased::__pyo3__richcmp__( + match _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestEnumUnaliased, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + ) { + ::std::result::Result::Ok(value) => value, + ::std::result::Result::Err(_) => { + return _pyo3::callback::convert(py, py.NotImplemented()); + } + }, + py, + match _pyo3::impl_::extract_argument::extract_argument( + py.from_borrowed_ptr::<_pyo3::PyAny>(arg0), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + "other", + ) { + ::std::result::Result::Ok(value) => value, + ::std::result::Result::Err(_) => { + return _pyo3::callback::convert(py, py.NotImplemented()); + } + }, + match _pyo3::class::basic::CompareOp::from_raw(arg1) + .ok_or_else(|| _pyo3::exceptions::PyValueError::new_err( + "invalid comparison operator", + )) + { + ::std::result::Result::Ok(value) => value, + ::std::result::Result::Err(_) => { + return _pyo3::callback::convert(py, py.NotImplemented()); + } + }, + ), + ) + } + } + #[doc(hidden)] + pub struct Pyo3MethodsInventoryForPyTestEnumUnaliased { + items: _pyo3::impl_::pyclass::PyClassItems, + } + impl Pyo3MethodsInventoryForPyTestEnumUnaliased { + pub const fn new(items: _pyo3::impl_::pyclass::PyClassItems) -> Self { + Self { items } + } + } + impl _pyo3::impl_::pyclass::PyClassInventory + for Pyo3MethodsInventoryForPyTestEnumUnaliased { + fn items(&self) -> &_pyo3::impl_::pyclass::PyClassItems { + &self.items + } + } + impl ::inventory::Collect for Pyo3MethodsInventoryForPyTestEnumUnaliased { + #[inline] + fn registry() -> &'static ::inventory::Registry { + static REGISTRY: ::inventory::Registry = ::inventory::Registry::new(); + ®ISTRY + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + impl PyTestEnumUnaliased { + fn __pyo3__repr__(&self) -> &'static str { + match self { + PyTestEnumUnaliased::One => "TestEnumUnaliased.One", + PyTestEnumUnaliased::Two => "TestEnumUnaliased.Two", + } + } + fn __pyo3__int__(&self) -> isize { + match self { + PyTestEnumUnaliased::One => PyTestEnumUnaliased::One as isize, + PyTestEnumUnaliased::Two => PyTestEnumUnaliased::Two as isize, + } + } + fn __pyo3__richcmp__( + &self, + py: _pyo3::Python, + other: &_pyo3::PyAny, + op: _pyo3::basic::CompareOp, + ) -> _pyo3::PyResult<_pyo3::PyObject> { + use _pyo3::conversion::ToPyObject; + use ::core::result::Result::*; + match op { + _pyo3::basic::CompareOp::Eq => { + let self_val = self.__pyo3__int__(); + if let Ok(i) = other.extract::() { + return Ok((self_val == i).to_object(py)); + } + if let Ok(other) = other.extract::<_pyo3::PyRef>() { + return Ok((self_val == other.__pyo3__int__()).to_object(py)); + } + return Ok(py.NotImplemented()); + } + _pyo3::basic::CompareOp::Ne => { + let self_val = self.__pyo3__int__(); + if let Ok(i) = other.extract::() { + return Ok((self_val != i).to_object(py)); + } + if let Ok(other) = other.extract::<_pyo3::PyRef>() { + return Ok((self_val != other.__pyo3__int__()).to_object(py)); + } + return Ok(py.NotImplemented()); + } + _ => Ok(py.NotImplemented()), + } + } + } + }; + #[automatically_derived] + impl ::core::marker::Copy for PyTestEnumUnaliased {} + #[automatically_derived] + impl ::core::clone::Clone for PyTestEnumUnaliased { + #[inline] + fn clone(&self) -> PyTestEnumUnaliased { + *self + } + } + impl From for TestEnum { + fn from(item: PyTestEnumUnaliased) -> Self { + match item { + PyTestEnumUnaliased::One => Self::One, + PyTestEnumUnaliased::Two => Self::Two, + } + } + } + impl From<&PyTestEnumUnaliased> for TestEnum { + fn from(item: &PyTestEnumUnaliased) -> Self { + Self::from(*item) + } + } + impl From for PyTestEnumUnaliased { + fn from(item: TestEnum) -> Self { + match item { + TestEnum::One => PyTestEnumUnaliased::One, + TestEnum::Two => PyTestEnumUnaliased::Two, + } + } + } + impl From<&TestEnum> for PyTestEnumUnaliased { + fn from(item: &TestEnum) -> Self { + Self::from(*item) + } + } + impl ::rigetti_pyo3::PyWrapper for PyTestEnumUnaliased { + type Inner = TestEnum; + } + impl AsRef for PyTestEnumUnaliased { + fn as_ref(&self) -> &TestEnum { + match self { + PyTestEnumUnaliased::One => &TestEnum::One, + PyTestEnumUnaliased::Two => &TestEnum::Two, + } + } + } + impl ::rigetti_pyo3::pyo3::conversion::ToPyObject for PyTestEnumUnaliased { + fn to_object( + &self, + py: ::rigetti_pyo3::pyo3::Python, + ) -> ::rigetti_pyo3::pyo3::PyObject { + let cell = ::rigetti_pyo3::pyo3::PyCell::new(py, self.clone()) + .unwrap_or_else(|err| { + ::core::panicking::panic_fmt( + format_args!( + "failed to create {0} on Python heap: {1}", + "PyTestEnumUnaliased", err, + ), + ); + }); + cell.to_object(py) + } + } + #[allow(clippy::use_self)] + impl ::rigetti_pyo3::ToPython for TestEnum { + fn to_python( + &self, + _py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult { + { Ok(PyTestEnumUnaliased::from(self)) } + } + } + #[allow(clippy::use_self)] + impl<'a> ::rigetti_pyo3::ToPython for &'a TestEnum { + fn to_python( + &self, + _py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult { + { + >::to_python(*self, _py) + } + } + } + #[allow(clippy::use_self)] + impl ::rigetti_pyo3::PyTryFrom for TestEnum { + fn py_try_from( + _py: ::rigetti_pyo3::pyo3::Python, + item: &PyTestEnumUnaliased, + ) -> ::rigetti_pyo3::pyo3::PyResult { + { Ok(*item.as_ref()) } + } + } + pub enum PyTestEnumAliased { + NONE, + Two, + } + const _: () = { + use ::pyo3 as _pyo3; + unsafe impl _pyo3::type_object::PyTypeInfo for PyTestEnumAliased { + type AsRefTarget = _pyo3::PyCell; + const NAME: &'static str = "TestEnumAliased"; + const MODULE: ::std::option::Option<&'static str> = ::core::option::Option::None; + #[inline] + fn type_object_raw(py: _pyo3::Python<'_>) -> *mut _pyo3::ffi::PyTypeObject { + ::lazy_type_object() + .get_or_init(py) + .as_type_ptr() + } + } + impl _pyo3::PyClass for PyTestEnumAliased { + type Frozen = _pyo3::pyclass::boolean_struct::False; + } + impl<'a, 'py> _pyo3::impl_::extract_argument::PyFunctionArgument<'a, 'py> + for &'a PyTestEnumAliased { + type Holder = ::std::option::Option<_pyo3::PyRef<'py, PyTestEnumAliased>>; + #[inline] + fn extract( + obj: &'py _pyo3::PyAny, + holder: &'a mut Self::Holder, + ) -> _pyo3::PyResult { + _pyo3::impl_::extract_argument::extract_pyclass_ref(obj, holder) + } + } + impl<'a, 'py> _pyo3::impl_::extract_argument::PyFunctionArgument<'a, 'py> + for &'a mut PyTestEnumAliased { + type Holder = ::std::option::Option<_pyo3::PyRefMut<'py, PyTestEnumAliased>>; + #[inline] + fn extract( + obj: &'py _pyo3::PyAny, + holder: &'a mut Self::Holder, + ) -> _pyo3::PyResult { + _pyo3::impl_::extract_argument::extract_pyclass_ref_mut(obj, holder) + } + } + impl _pyo3::IntoPy<_pyo3::PyObject> for PyTestEnumAliased { + fn into_py(self, py: _pyo3::Python) -> _pyo3::PyObject { + _pyo3::IntoPy::into_py(_pyo3::Py::new(py, self).unwrap(), py) + } + } + impl _pyo3::impl_::pyclass::PyClassImpl for PyTestEnumAliased { + const IS_BASETYPE: bool = false; + const IS_SUBCLASS: bool = false; + const IS_MAPPING: bool = false; + const IS_SEQUENCE: bool = false; + type BaseType = _pyo3::PyAny; + type ThreadChecker = _pyo3::impl_::pyclass::SendablePyClass< + PyTestEnumAliased, + >; + type Inventory = Pyo3MethodsInventoryForPyTestEnumAliased; + type PyClassMutability = <<_pyo3::PyAny as _pyo3::impl_::pyclass::PyClassBaseType>::PyClassMutability as _pyo3::impl_::pycell::PyClassMutability>::MutableChild; + type Dict = _pyo3::impl_::pyclass::PyClassDummySlot; + type WeakRef = _pyo3::impl_::pyclass::PyClassDummySlot; + type BaseNativeType = _pyo3::PyAny; + fn items_iter() -> _pyo3::impl_::pyclass::PyClassItemsIter { + use _pyo3::impl_::pyclass::*; + let collector = PyClassImplCollector::::new(); + static INTRINSIC_ITEMS: PyClassItems = PyClassItems { + methods: &[ + _pyo3::class::PyMethodDefType::ClassAttribute({ + _pyo3::class::PyClassAttributeDef::new( + { "NONE\0" }, + _pyo3::impl_::pymethods::PyClassAttributeFactory( + PyTestEnumAliased::__pymethod_NONE__, + ), + ) + }), + _pyo3::class::PyMethodDefType::ClassAttribute({ + _pyo3::class::PyClassAttributeDef::new( + { "Two\0" }, + _pyo3::impl_::pymethods::PyClassAttributeFactory( + PyTestEnumAliased::__pymethod_Two__, + ), + ) + }), + ], + slots: &[ + { + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::reprfunc( + _slf, + PyTestEnumAliased::__pymethod___default___pyo3__repr______, + ) + } + _pyo3::ffi::PyType_Slot { + slot: _pyo3::ffi::Py_tp_repr, + pfunc: trampoline as _pyo3::ffi::reprfunc as _, + } + }, + { + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::unaryfunc( + _slf, + PyTestEnumAliased::__pymethod___default___pyo3__int______, + ) + } + _pyo3::ffi::PyType_Slot { + slot: _pyo3::ffi::Py_nb_int, + pfunc: trampoline as _pyo3::ffi::unaryfunc as _, + } + }, + { + unsafe extern "C" fn trampoline( + _slf: *mut _pyo3::ffi::PyObject, + arg0: *mut _pyo3::ffi::PyObject, + arg1: ::std::os::raw::c_int, + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::impl_::trampoline::richcmpfunc( + _slf, + arg0, + arg1, + PyTestEnumAliased::__pymethod___default___pyo3__richcmp______, + ) + } + _pyo3::ffi::PyType_Slot { + slot: _pyo3::ffi::Py_tp_richcompare, + pfunc: trampoline as _pyo3::ffi::richcmpfunc as _, + } + }, + ], + }; + PyClassItemsIter::new( + &INTRINSIC_ITEMS, + ::std::boxed::Box::new( + ::std::iter::Iterator::map( + _pyo3::inventory::iter::< + ::Inventory, + >(), + _pyo3::impl_::pyclass::PyClassInventory::items, + ), + ), + ) + } + fn doc(py: _pyo3::Python<'_>) -> _pyo3::PyResult<&'static ::std::ffi::CStr> { + use _pyo3::impl_::pyclass::*; + static DOC: _pyo3::once_cell::GILOnceCell< + ::std::borrow::Cow<'static, ::std::ffi::CStr>, + > = _pyo3::once_cell::GILOnceCell::new(); + DOC.get_or_try_init( + py, + || { + let collector = PyClassImplCollector::::new(); + build_pyclass_doc( + ::NAME, + "\0", + ::std::option::Option::None + .or_else(|| collector.new_text_signature()), + ) + }, + ) + .map(::std::ops::Deref::deref) + } + fn lazy_type_object() -> &'static _pyo3::impl_::pyclass::LazyTypeObject< + Self, + > { + use _pyo3::impl_::pyclass::LazyTypeObject; + static TYPE_OBJECT: LazyTypeObject = LazyTypeObject::new(); + &TYPE_OBJECT + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + impl PyTestEnumAliased { + fn __pymethod_NONE__( + py: _pyo3::Python<'_>, + ) -> _pyo3::PyResult<_pyo3::PyObject> { + ::std::result::Result::Ok( + _pyo3::IntoPy::into_py(PyTestEnumAliased::NONE, py), + ) + } + fn __pymethod_Two__( + py: _pyo3::Python<'_>, + ) -> _pyo3::PyResult<_pyo3::PyObject> { + ::std::result::Result::Ok( + _pyo3::IntoPy::into_py(PyTestEnumAliased::Two, py), + ) + } + unsafe fn __pymethod___default___pyo3__repr______( + py: _pyo3::Python<'_>, + _raw_slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestEnumAliased::__pyo3__repr__; + let _slf = _raw_slf; + _pyo3::callback::convert( + py, + PyTestEnumAliased::__pyo3__repr__( + _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestEnumAliased, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + ), + ) + } + unsafe fn __pymethod___default___pyo3__int______( + py: _pyo3::Python<'_>, + _raw_slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestEnumAliased::__pyo3__int__; + let _slf = _raw_slf; + _pyo3::callback::convert( + py, + PyTestEnumAliased::__pyo3__int__( + _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestEnumAliased, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + ), + ) + } + unsafe fn __pymethod___default___pyo3__richcmp______( + py: _pyo3::Python<'_>, + _raw_slf: *mut _pyo3::ffi::PyObject, + arg0: *mut _pyo3::ffi::PyObject, + arg1: ::std::os::raw::c_int, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + let function = PyTestEnumAliased::__pyo3__richcmp__; + let _slf = _raw_slf; + _pyo3::callback::convert( + py, + PyTestEnumAliased::__pyo3__richcmp__( + match _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestEnumAliased, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + ) { + ::std::result::Result::Ok(value) => value, + ::std::result::Result::Err(_) => { + return _pyo3::callback::convert(py, py.NotImplemented()); + } + }, + py, + match _pyo3::impl_::extract_argument::extract_argument( + py.from_borrowed_ptr::<_pyo3::PyAny>(arg0), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + "other", + ) { + ::std::result::Result::Ok(value) => value, + ::std::result::Result::Err(_) => { + return _pyo3::callback::convert(py, py.NotImplemented()); + } + }, + match _pyo3::class::basic::CompareOp::from_raw(arg1) + .ok_or_else(|| _pyo3::exceptions::PyValueError::new_err( + "invalid comparison operator", + )) + { + ::std::result::Result::Ok(value) => value, + ::std::result::Result::Err(_) => { + return _pyo3::callback::convert(py, py.NotImplemented()); + } + }, + ), + ) + } + } + #[doc(hidden)] + pub struct Pyo3MethodsInventoryForPyTestEnumAliased { + items: _pyo3::impl_::pyclass::PyClassItems, + } + impl Pyo3MethodsInventoryForPyTestEnumAliased { + pub const fn new(items: _pyo3::impl_::pyclass::PyClassItems) -> Self { + Self { items } + } + } + impl _pyo3::impl_::pyclass::PyClassInventory + for Pyo3MethodsInventoryForPyTestEnumAliased { + fn items(&self) -> &_pyo3::impl_::pyclass::PyClassItems { + &self.items + } + } + impl ::inventory::Collect for Pyo3MethodsInventoryForPyTestEnumAliased { + #[inline] + fn registry() -> &'static ::inventory::Registry { + static REGISTRY: ::inventory::Registry = ::inventory::Registry::new(); + ®ISTRY + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + impl PyTestEnumAliased { + fn __pyo3__repr__(&self) -> &'static str { + match self { + PyTestEnumAliased::NONE => "TestEnumAliased.NONE", + PyTestEnumAliased::Two => "TestEnumAliased.Two", + } + } + fn __pyo3__int__(&self) -> isize { + match self { + PyTestEnumAliased::NONE => PyTestEnumAliased::NONE as isize, + PyTestEnumAliased::Two => PyTestEnumAliased::Two as isize, + } + } + fn __pyo3__richcmp__( + &self, + py: _pyo3::Python, + other: &_pyo3::PyAny, + op: _pyo3::basic::CompareOp, + ) -> _pyo3::PyResult<_pyo3::PyObject> { + use _pyo3::conversion::ToPyObject; + use ::core::result::Result::*; + match op { + _pyo3::basic::CompareOp::Eq => { + let self_val = self.__pyo3__int__(); + if let Ok(i) = other.extract::() { + return Ok((self_val == i).to_object(py)); + } + if let Ok(other) = other.extract::<_pyo3::PyRef>() { + return Ok((self_val == other.__pyo3__int__()).to_object(py)); + } + return Ok(py.NotImplemented()); + } + _pyo3::basic::CompareOp::Ne => { + let self_val = self.__pyo3__int__(); + if let Ok(i) = other.extract::() { + return Ok((self_val != i).to_object(py)); + } + if let Ok(other) = other.extract::<_pyo3::PyRef>() { + return Ok((self_val != other.__pyo3__int__()).to_object(py)); + } + return Ok(py.NotImplemented()); + } + _ => Ok(py.NotImplemented()), + } + } + } + }; + #[automatically_derived] + impl ::core::marker::Copy for PyTestEnumAliased {} + #[automatically_derived] + impl ::core::clone::Clone for PyTestEnumAliased { + #[inline] + fn clone(&self) -> PyTestEnumAliased { + *self + } + } + impl From for TestEnum { + fn from(item: PyTestEnumAliased) -> Self { + match item { + PyTestEnumAliased::NONE => Self::One, + PyTestEnumAliased::Two => Self::Two, + } + } + } + impl From<&PyTestEnumAliased> for TestEnum { + fn from(item: &PyTestEnumAliased) -> Self { + Self::from(*item) + } + } + impl From for PyTestEnumAliased { + fn from(item: TestEnum) -> Self { + match item { + TestEnum::One => PyTestEnumAliased::NONE, + TestEnum::Two => PyTestEnumAliased::Two, + } + } + } + impl From<&TestEnum> for PyTestEnumAliased { + fn from(item: &TestEnum) -> Self { + Self::from(*item) + } + } + impl ::rigetti_pyo3::PyWrapper for PyTestEnumAliased { + type Inner = TestEnum; + } + impl AsRef for PyTestEnumAliased { + fn as_ref(&self) -> &TestEnum { + match self { + PyTestEnumAliased::NONE => &TestEnum::One, + PyTestEnumAliased::Two => &TestEnum::Two, + } + } + } + impl ::rigetti_pyo3::pyo3::conversion::ToPyObject for PyTestEnumAliased { + fn to_object( + &self, + py: ::rigetti_pyo3::pyo3::Python, + ) -> ::rigetti_pyo3::pyo3::PyObject { + let cell = ::rigetti_pyo3::pyo3::PyCell::new(py, self.clone()) + .unwrap_or_else(|err| { + ::core::panicking::panic_fmt( + format_args!( + "failed to create {0} on Python heap: {1}", + "PyTestEnumAliased", err, + ), + ); + }); + cell.to_object(py) + } + } + #[allow(clippy::use_self)] + impl ::rigetti_pyo3::ToPython for TestEnum { + fn to_python( + &self, + _py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult { + { Ok(PyTestEnumAliased::from(self)) } + } + } + #[allow(clippy::use_self)] + impl<'a> ::rigetti_pyo3::ToPython for &'a TestEnum { + fn to_python( + &self, + _py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult { + { + >::to_python(*self, _py) + } + } + } + #[allow(clippy::use_self)] + impl ::rigetti_pyo3::PyTryFrom for TestEnum { + fn py_try_from( + _py: ::rigetti_pyo3::pyo3::Python, + item: &PyTestEnumAliased, + ) -> ::rigetti_pyo3::pyo3::PyResult { + { Ok(*item.as_ref()) } + } + } + #[repr(transparent)] + #[allow(clippy::use_self)] + pub struct PyTestStruct(TestStruct); + #[automatically_derived] + #[allow(clippy::use_self)] + impl ::core::clone::Clone for PyTestStruct { + #[inline] + fn clone(&self) -> PyTestStruct { + PyTestStruct(::core::clone::Clone::clone(&self.0)) + } + } + const _: () = { + use ::pyo3 as _pyo3; + unsafe impl _pyo3::type_object::PyTypeInfo for PyTestStruct { + type AsRefTarget = _pyo3::PyCell; + const NAME: &'static str = "TestStruct"; + const MODULE: ::std::option::Option<&'static str> = ::core::option::Option::None; + #[inline] + fn type_object_raw(py: _pyo3::Python<'_>) -> *mut _pyo3::ffi::PyTypeObject { + ::lazy_type_object() + .get_or_init(py) + .as_type_ptr() + } + } + impl _pyo3::PyClass for PyTestStruct { + type Frozen = _pyo3::pyclass::boolean_struct::False; + } + impl<'a, 'py> _pyo3::impl_::extract_argument::PyFunctionArgument<'a, 'py> + for &'a PyTestStruct { + type Holder = ::std::option::Option<_pyo3::PyRef<'py, PyTestStruct>>; + #[inline] + fn extract( + obj: &'py _pyo3::PyAny, + holder: &'a mut Self::Holder, + ) -> _pyo3::PyResult { + _pyo3::impl_::extract_argument::extract_pyclass_ref(obj, holder) + } + } + impl<'a, 'py> _pyo3::impl_::extract_argument::PyFunctionArgument<'a, 'py> + for &'a mut PyTestStruct { + type Holder = ::std::option::Option<_pyo3::PyRefMut<'py, PyTestStruct>>; + #[inline] + fn extract( + obj: &'py _pyo3::PyAny, + holder: &'a mut Self::Holder, + ) -> _pyo3::PyResult { + _pyo3::impl_::extract_argument::extract_pyclass_ref_mut(obj, holder) + } + } + impl _pyo3::IntoPy<_pyo3::PyObject> for PyTestStruct { + fn into_py(self, py: _pyo3::Python) -> _pyo3::PyObject { + _pyo3::IntoPy::into_py(_pyo3::Py::new(py, self).unwrap(), py) + } + } + impl _pyo3::impl_::pyclass::PyClassImpl for PyTestStruct { + const IS_BASETYPE: bool = false; + const IS_SUBCLASS: bool = false; + const IS_MAPPING: bool = false; + const IS_SEQUENCE: bool = false; + type BaseType = _pyo3::PyAny; + type ThreadChecker = _pyo3::impl_::pyclass::SendablePyClass; + type Inventory = Pyo3MethodsInventoryForPyTestStruct; + type PyClassMutability = <<_pyo3::PyAny as _pyo3::impl_::pyclass::PyClassBaseType>::PyClassMutability as _pyo3::impl_::pycell::PyClassMutability>::MutableChild; + type Dict = _pyo3::impl_::pyclass::PyClassDummySlot; + type WeakRef = _pyo3::impl_::pyclass::PyClassDummySlot; + type BaseNativeType = _pyo3::PyAny; + fn items_iter() -> _pyo3::impl_::pyclass::PyClassItemsIter { + use _pyo3::impl_::pyclass::*; + let collector = PyClassImplCollector::::new(); + static INTRINSIC_ITEMS: PyClassItems = PyClassItems { + methods: &[], + slots: &[], + }; + PyClassItemsIter::new( + &INTRINSIC_ITEMS, + ::std::boxed::Box::new( + ::std::iter::Iterator::map( + _pyo3::inventory::iter::< + ::Inventory, + >(), + _pyo3::impl_::pyclass::PyClassInventory::items, + ), + ), + ) + } + fn doc(py: _pyo3::Python<'_>) -> _pyo3::PyResult<&'static ::std::ffi::CStr> { + use _pyo3::impl_::pyclass::*; + static DOC: _pyo3::once_cell::GILOnceCell< + ::std::borrow::Cow<'static, ::std::ffi::CStr>, + > = _pyo3::once_cell::GILOnceCell::new(); + DOC.get_or_try_init( + py, + || { + let collector = PyClassImplCollector::::new(); + build_pyclass_doc( + ::NAME, + "\0", + ::std::option::Option::None + .or_else(|| collector.new_text_signature()), + ) + }, + ) + .map(::std::ops::Deref::deref) + } + fn lazy_type_object() -> &'static _pyo3::impl_::pyclass::LazyTypeObject< + Self, + > { + use _pyo3::impl_::pyclass::LazyTypeObject; + static TYPE_OBJECT: LazyTypeObject = LazyTypeObject::new(); + &TYPE_OBJECT + } + } + #[doc(hidden)] + #[allow(non_snake_case)] + impl PyTestStruct {} + #[doc(hidden)] + pub struct Pyo3MethodsInventoryForPyTestStruct { + items: _pyo3::impl_::pyclass::PyClassItems, + } + impl Pyo3MethodsInventoryForPyTestStruct { + pub const fn new(items: _pyo3::impl_::pyclass::PyClassItems) -> Self { + Self { items } + } + } + impl _pyo3::impl_::pyclass::PyClassInventory + for Pyo3MethodsInventoryForPyTestStruct { + fn items(&self) -> &_pyo3::impl_::pyclass::PyClassItems { + &self.items + } + } + impl ::inventory::Collect for Pyo3MethodsInventoryForPyTestStruct { + #[inline] + fn registry() -> &'static ::inventory::Registry { + static REGISTRY: ::inventory::Registry = ::inventory::Registry::new(); + ®ISTRY + } + } + }; + impl ::rigetti_pyo3::PyTryFrom for TestStruct { + fn py_try_from( + py: ::rigetti_pyo3::pyo3::Python, + item: &PyTestStruct, + ) -> ::rigetti_pyo3::pyo3::PyResult { + Ok(item.0.clone()) + } + } + impl ::rigetti_pyo3::PyTryFrom<::rigetti_pyo3::pyo3::PyAny> for PyTestStruct { + fn py_try_from( + py: ::rigetti_pyo3::pyo3::Python, + item: &::rigetti_pyo3::pyo3::PyAny, + ) -> ::rigetti_pyo3::pyo3::PyResult { + item.extract() + } + } + impl ::rigetti_pyo3::PyTryFrom for PyTestStruct { + fn py_try_from( + py: ::rigetti_pyo3::pyo3::Python, + item: &PyTestStruct, + ) -> ::rigetti_pyo3::pyo3::PyResult { + Ok(item.clone()) + } + } + #[allow(clippy::use_self)] + impl ::rigetti_pyo3::ToPython for TestStruct { + fn to_python( + &self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult { + { Ok(PyTestStruct::from(self.clone())) } + } + } + #[allow(clippy::use_self)] + impl<'a> ::rigetti_pyo3::ToPython for &'a TestStruct { + fn to_python( + &self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult { + { + >::to_python(*self, py) + } + } + } + #[allow(clippy::use_self)] + impl ::rigetti_pyo3::ToPython<::rigetti_pyo3::pyo3::Py<::rigetti_pyo3::pyo3::PyAny>> + for PyTestStruct { + fn to_python( + &self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult< + ::rigetti_pyo3::pyo3::Py<::rigetti_pyo3::pyo3::PyAny>, + > { + { Ok(::to_object(self, py)) } + } + } + #[allow(clippy::use_self)] + impl< + 'a, + > ::rigetti_pyo3::ToPython<::rigetti_pyo3::pyo3::Py<::rigetti_pyo3::pyo3::PyAny>> + for &'a PyTestStruct { + fn to_python( + &self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult< + ::rigetti_pyo3::pyo3::Py<::rigetti_pyo3::pyo3::PyAny>, + > { + { + , + >>::to_python(*self, py) + } + } + } + impl From for TestStruct { + fn from(wrapper: PyTestStruct) -> Self { + wrapper.0 + } + } + impl From for PyTestStruct { + fn from(inner: TestStruct) -> Self { + Self(inner) + } + } + impl From<&TestStruct> for PyTestStruct { + fn from(inner: &TestStruct) -> Self { + Self(inner.clone()) + } + } + impl AsRef for PyTestStruct { + fn as_ref(&self) -> &TestStruct { + &self.0 + } + } + impl ::rigetti_pyo3::PyWrapper for PyTestStruct { + type Inner = TestStruct; + } + impl ::rigetti_pyo3::pyo3::conversion::ToPyObject for PyTestStruct { + fn to_object( + &self, + py: ::rigetti_pyo3::pyo3::Python, + ) -> ::rigetti_pyo3::pyo3::PyObject { + #[allow(clippy::use_self)] + const NAME: &'static str = "PyTestStruct"; + let cell = ::rigetti_pyo3::pyo3::PyCell::new(py, self.clone()) + .unwrap_or_else(|err| { + { + ::core::panicking::panic_fmt( + format_args!( + "failed to create {0} on Python heap: {1}", NAME, err, + ), + ); + } + }); + ::rigetti_pyo3::pyo3::conversion::ToPyObject::to_object(&cell, py) + } + } + impl AsMut<::Inner> for PyTestStruct { + fn as_mut(&mut self) -> &mut ::Inner { + &mut self.0 + } + } + impl PyTestStruct { + ///Get the test_enum_unaliased field from Python. Annotated with `@property`. + fn get_test_enum_unaliased( + &self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult { + use ::rigetti_pyo3::{PyWrapper, ToPython}; + let inner = &self.as_inner().test_enum_unaliased; + { + let inner: PyTestEnumUnaliased = ::rigetti_pyo3::ToPython::< + PyTestEnumUnaliased, + >::to_python(&inner, py)?; + Ok::<_, ::rigetti_pyo3::pyo3::PyErr>(inner) + } + } + ///Set the test_enum_unaliased field from Python. Annotated with `@test_enum_unaliased.setter`. + fn set_test_enum_unaliased( + &mut self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + from: PyTestEnumUnaliased, + ) -> ::rigetti_pyo3::pyo3::PyResult<()> { + use ::rigetti_pyo3::{PyTryFrom, PyWrapperMut}; + let from = &from; + let new_val: TestEnum = { + <_ as ::rigetti_pyo3::PyTryFrom< + PyTestEnumUnaliased, + >>::py_try_from(py, from) + }?; + self.as_inner_mut().test_enum_unaliased = new_val; + Ok(()) + } + ///Get the test_enum_aliased field from Python. Annotated with `@property`. + fn get_test_enum_aliased( + &self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + ) -> ::rigetti_pyo3::pyo3::PyResult { + use ::rigetti_pyo3::{PyWrapper, ToPython}; + let inner = &self.as_inner().test_enum_aliased; + { + let inner: PyTestEnumAliased = ::rigetti_pyo3::ToPython::< + PyTestEnumAliased, + >::to_python(&inner, py)?; + Ok::<_, ::rigetti_pyo3::pyo3::PyErr>(inner) + } + } + ///Set the test_enum_aliased field from Python. Annotated with `@test_enum_aliased.setter`. + fn set_test_enum_aliased( + &mut self, + py: ::rigetti_pyo3::pyo3::Python<'_>, + from: PyTestEnumAliased, + ) -> ::rigetti_pyo3::pyo3::PyResult<()> { + use ::rigetti_pyo3::{PyTryFrom, PyWrapperMut}; + let from = &from; + let new_val: TestEnum = { + <_ as ::rigetti_pyo3::PyTryFrom< + PyTestEnumAliased, + >>::py_try_from(py, from) + }?; + self.as_inner_mut().test_enum_aliased = new_val; + Ok(()) + } + } + const _: () = { + use ::pyo3 as _pyo3; + #[allow(non_upper_case_globals)] + const _: () = { + static __INVENTORY: ::inventory::Node = ::inventory::Node { + value: &{ + type Inventory = ::Inventory; + Inventory::new(_pyo3::impl_::pyclass::PyClassItems { + methods: &[ + _pyo3::class::PyMethodDefType::Getter( + _pyo3::class::PyGetterDef::new( + "test_enum_unaliased\0", + _pyo3::impl_::pymethods::PyGetter( + PyTestStruct::__pymethod_get_get_test_enum_unaliased__, + ), + "Get the test_enum_unaliased field from Python. Annotated with `@property`.\u{0}", + ), + ), + _pyo3::class::PyMethodDefType::Setter( + _pyo3::class::PySetterDef::new( + "test_enum_unaliased\0", + _pyo3::impl_::pymethods::PySetter( + PyTestStruct::__pymethod_set_set_test_enum_unaliased__, + ), + "Set the test_enum_unaliased field from Python. Annotated with `@test_enum_unaliased.setter`.\u{0}", + ), + ), + _pyo3::class::PyMethodDefType::Getter( + _pyo3::class::PyGetterDef::new( + "test_enum_aliased\0", + _pyo3::impl_::pymethods::PyGetter( + PyTestStruct::__pymethod_get_get_test_enum_aliased__, + ), + "Get the test_enum_aliased field from Python. Annotated with `@property`.\u{0}", + ), + ), + _pyo3::class::PyMethodDefType::Setter( + _pyo3::class::PySetterDef::new( + "test_enum_aliased\0", + _pyo3::impl_::pymethods::PySetter( + PyTestStruct::__pymethod_set_set_test_enum_aliased__, + ), + "Set the test_enum_aliased field from Python. Annotated with `@test_enum_aliased.setter`.\u{0}", + ), + ), + ], + slots: &[], + }) + }, + next: ::inventory::core::cell::UnsafeCell::new( + ::inventory::core::option::Option::None, + ), + }; + #[link_section = ".text.startup"] + unsafe extern "C" fn __ctor() { + unsafe { + ::inventory::ErasedNode::submit(__INVENTORY.value, &__INVENTORY) + } + } + #[used] + #[link_section = ".init_array"] + static __CTOR: unsafe extern "C" fn() = __ctor; + }; + #[doc(hidden)] + #[allow(non_snake_case)] + impl PyTestStruct { + unsafe fn __pymethod_get_get_test_enum_unaliased__( + py: _pyo3::Python<'_>, + _slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + _pyo3::callback::convert( + py, + PyTestStruct::get_test_enum_unaliased( + _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestStruct, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + py, + ), + ) + } + unsafe fn __pymethod_set_set_test_enum_unaliased__( + py: _pyo3::Python<'_>, + _slf: *mut _pyo3::ffi::PyObject, + _value: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<::std::os::raw::c_int> { + let _value = py + .from_borrowed_ptr_or_opt(_value) + .ok_or_else(|| { + _pyo3::exceptions::PyAttributeError::new_err( + "can't delete attribute", + ) + })?; + let _val = _pyo3::FromPyObject::extract(_value)?; + _pyo3::callback::convert( + py, + PyTestStruct::set_test_enum_unaliased( + _pyo3::impl_::extract_argument::extract_pyclass_ref_mut::< + PyTestStruct, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + py, + _val, + ), + ) + } + unsafe fn __pymethod_get_get_test_enum_aliased__( + py: _pyo3::Python<'_>, + _slf: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + _pyo3::callback::convert( + py, + PyTestStruct::get_test_enum_aliased( + _pyo3::impl_::extract_argument::extract_pyclass_ref::< + PyTestStruct, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + py, + ), + ) + } + unsafe fn __pymethod_set_set_test_enum_aliased__( + py: _pyo3::Python<'_>, + _slf: *mut _pyo3::ffi::PyObject, + _value: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<::std::os::raw::c_int> { + let _value = py + .from_borrowed_ptr_or_opt(_value) + .ok_or_else(|| { + _pyo3::exceptions::PyAttributeError::new_err( + "can't delete attribute", + ) + })?; + let _val = _pyo3::FromPyObject::extract(_value)?; + _pyo3::callback::convert( + py, + PyTestStruct::set_test_enum_aliased( + _pyo3::impl_::extract_argument::extract_pyclass_ref_mut::< + PyTestStruct, + >( + py.from_borrowed_ptr::<_pyo3::PyAny>(_slf), + &mut { + _pyo3::impl_::extract_argument::FunctionArgumentHolder::INIT + }, + )?, + py, + _val, + ), + ) + } + } + }; + impl PyTestStruct { + fn __new__() -> Self { + Self(TestStruct { + test_enum_unaliased: TestEnum::One, + test_enum_aliased: TestEnum::One, + }) + } + } + const _: () = { + use ::pyo3 as _pyo3; + #[allow(non_upper_case_globals)] + const _: () = { + static __INVENTORY: ::inventory::Node = ::inventory::Node { + value: &{ + type Inventory = ::Inventory; + Inventory::new(_pyo3::impl_::pyclass::PyClassItems { + methods: &[], + slots: &[ + _pyo3::ffi::PyType_Slot { + slot: _pyo3::ffi::Py_tp_new, + pfunc: { + unsafe extern "C" fn trampoline( + subtype: *mut _pyo3::ffi::PyTypeObject, + args: *mut _pyo3::ffi::PyObject, + kwargs: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { + use _pyo3::impl_::pyclass::*; + impl PyClassNewTextSignature + for PyClassImplCollector { + #[inline] + fn new_text_signature( + self, + ) -> ::std::option::Option<&'static str> { + ::std::option::Option::Some("()") + } + } + _pyo3::impl_::trampoline::newfunc( + subtype, + args, + kwargs, + PyTestStruct::__pymethod___new____, + ) + } + trampoline + } as _pyo3::ffi::newfunc as _, + }, + ], + }) + }, + next: ::inventory::core::cell::UnsafeCell::new( + ::inventory::core::option::Option::None, + ), + }; + #[link_section = ".text.startup"] + unsafe extern "C" fn __ctor() { + unsafe { + ::inventory::ErasedNode::submit(__INVENTORY.value, &__INVENTORY) + } + } + #[used] + #[link_section = ".init_array"] + static __CTOR: unsafe extern "C" fn() = __ctor; + }; + #[doc(hidden)] + #[allow(non_snake_case)] + impl PyTestStruct { + unsafe fn __pymethod___new____( + py: _pyo3::Python<'_>, + _slf: *mut _pyo3::ffi::PyTypeObject, + _args: *mut _pyo3::ffi::PyObject, + _kwargs: *mut _pyo3::ffi::PyObject, + ) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> { + use _pyo3::callback::IntoPyCallbackOutput; + let function = PyTestStruct::__new__; + const DESCRIPTION: _pyo3::impl_::extract_argument::FunctionDescription = _pyo3::impl_::extract_argument::FunctionDescription { + cls_name: ::std::option::Option::Some( + ::NAME, + ), + func_name: "__new__", + positional_parameter_names: &[], + positional_only_parameters: 0usize, + required_positional_parameters: 0usize, + keyword_only_parameters: &[], + }; + let mut output = [::std::option::Option::None; 0usize]; + let (_args, _kwargs) = DESCRIPTION + .extract_arguments_tuple_dict::< + _pyo3::impl_::extract_argument::NoVarargs, + _pyo3::impl_::extract_argument::NoVarkeywords, + >(py, _args, _kwargs, &mut output)?; + let result = PyTestStruct::__new__(); + let initializer: _pyo3::PyClassInitializer = result + .convert(py)?; + let cell = initializer.create_cell_from_subtype(py, _slf)?; + ::std::result::Result::Ok(cell as *mut _pyo3::ffi::PyObject) + } + } + }; +} +fn wrapper_tests(py: Python<'_>, m: &PyModule) -> PyResult<()> { + python::init_submodule("wrapper_tests", py, m) +} +#[doc(hidden)] +mod wrapper_tests { + pub(crate) struct MakeDef; + pub static DEF: ::pyo3::impl_::pymodule::ModuleDef = MakeDef::make_def(); + pub const NAME: &'static str = "wrapper_tests\u{0}"; + /// This autogenerated function is called by the python interpreter when importing + /// the module. + #[export_name = "PyInit_wrapper_tests"] + pub unsafe extern "C" fn init() -> *mut ::pyo3::ffi::PyObject { + ::pyo3::impl_::trampoline::module_init(|py| DEF.make_module(py)) + } +} +const _: () = { + use ::pyo3::impl_::pymodule as impl_; + impl wrapper_tests::MakeDef { + const fn make_def() -> impl_::ModuleDef { + const INITIALIZER: impl_::ModuleInitializer = impl_::ModuleInitializer( + wrapper_tests, + ); + unsafe { impl_::ModuleDef::new(wrapper_tests::NAME, "\0", INITIALIZER) } + } + } +}; +pub fn append_to_inittab() { + unsafe { + if ::pyo3::ffi::Py_IsInitialized() != 0 { + { + ::core::panicking::panic_fmt( + format_args!( + "called `append_to_inittab` but a Python interpreter is already running.", + ), + ); + }; + } + ::pyo3::ffi::PyImport_AppendInittab( + wrapper_tests::NAME.as_ptr() as *const ::std::os::raw::c_char, + ::std::option::Option::Some(wrapper_tests::init), + ); + }; +} diff --git a/tests/wrapper_tests.rs b/tests/wrapper_tests/mod.rs similarity index 69% rename from tests/wrapper_tests.rs rename to tests/wrapper_tests/mod.rs index 1bec7fe..ea25bc8 100644 --- a/tests/wrapper_tests.rs +++ b/tests/wrapper_tests/mod.rs @@ -77,31 +77,6 @@ fn wrapper_tests(py: Python<'_>, m: &PyModule) -> PyResult<()> { python::init_submodule("wrapper_tests", py, m) } -#[test] -fn test_enum_as_data_struct_member() { +pub fn append_to_inittab() { pyo3::append_to_inittab!(wrapper_tests); - pyo3::prepare_freethreaded_python(); - let result: PyResult<()> = Python::with_gil(|py| { - let code = r#" -from wrapper_tests import TestEnumUnaliased, TestEnumAliased, TestStruct, TestUnionEnum - -struct = TestStruct() - -assert struct.test_enum_unaliased == TestEnumUnaliased.One -assert struct.test_enum_aliased == TestEnumAliased.NONE - -struct.test_enum_unaliased = TestEnumUnaliased.Two -struct.test_enum_aliased = TestEnumAliased.Two - -assert struct.test_enum_unaliased == TestEnumUnaliased.Two -assert struct.test_enum_aliased == TestEnumAliased.Two - -assert TestUnionEnum.new_unit().is_unit() -"#; - PyModule::from_code(py, code, "example.py", "example")?; - - Ok(()) - }); - - result.expect("python code should execute without issue") }