You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PyInt does not implement PyClassBaseType, because it does not use pyobject_native_type!() but pyobject_native_type_core!(). As such, it cannot be subclassed.
Fixing this is not trivial because:
error[E0277]: the trait bound `pyo3_ffi::PyLongObject: PySizedLayout<types::num::PyInt>` is not satisfied
--> src\types\mod.rs:200:33
|
200 | type LayoutAsBase = $crate::impl_::pycell::PyClassObjectBase<$layout>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `PySizedLayout<types::num::PyInt>` is not implemented for `pyo3_ffi::PyLongObject`, which is required by `PyClassObjectBase<pyo3_ffi::PyLongObject>: PyClassObjectLayout<types::num::PyInt>`
|
::: src\types\num.rs:17:1
|
17 | pyobject_subclassable_native_type!(PyInt, ffi::PyLongObject);
| ------------------------------------------------------------ in this macro invocation
|
= help: the following other types implement trait `PySizedLayout<T>`:
<PyClassObject<T> as PySizedLayout<T>>
<_PyWeakReference as PySizedLayout<PyWeakrefReference>>
<pyo3_ffi::PyBaseExceptionObject as PySizedLayout<PyArithmeticError>>
<pyo3_ffi::PyBaseExceptionObject as PySizedLayout<PyAssertionError>>
<pyo3_ffi::PyBaseExceptionObject as PySizedLayout<PyAttributeError>>
<pyo3_ffi::PyBaseExceptionObject as PySizedLayout<PyBaseException>>
<pyo3_ffi::PyBaseExceptionObject as PySizedLayout<PyBaseExceptionGroup>>
<pyo3_ffi::PyBaseExceptionObject as PySizedLayout<PyBlockingIOError>>
and 74 others
note: required for `PyClassObjectBase<pyo3_ffi::PyLongObject>` to implement `PyClassObjectLayout<types::num::PyInt>`
--> src\pycell\impl_.rs:195:12
|
195 | impl<T, U> PyClassObjectLayout<T> for PyClassObjectBase<U>
| ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
196 | where
197 | U: PySizedLayout<T>,
| ---------------- unsatisfied trait bound introduced here
note: required by a bound in `PyClassBaseType::LayoutAsBase`
--> src\impl_\pyclass.rs:1131:24
|
1131 | type LayoutAsBase: PyClassObjectLayout<Self>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `PyClassBaseType::LayoutAsBase`
= note: this error originates in the macro `pyobject_subclassable_native_type` (in Nightly builds, run with -Z macro-backtrace for more info)
Steps to Reproduce
The following code:
use pyo3::prelude::*;use pyo3::types::PyInt;#[pyclass(extends=PyInt)]pubstructIntSubClass{}
Triggers the error:
error[E0277]: the trait bound `PyInt: PyClass` is not satisfied
--> src\lib.rs:4:1
|
4 | #[pyclass(extends=PyInt)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `PyClass` is not implemented for `PyInt`, which is required by `PyInt: PyClassBaseType`
|
= help: the trait `PyClass` is implemented for `IntSubClass`
= note: required for `PyInt` to implement `PyClassBaseType`
= note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
Backtrace
No response
Your operating system and version
Windows 11
Your Python version (python --version)
3.12
Your Rust version (rustc --version)
rustc 1.80.1 (3f5fd8dd4 2024-08-06)
Your PyO3 version
0.22.0
How did you install python? Did you use a virtualenv?
Bug Description
PyInt
does not implementPyClassBaseType
, because it does not usepyobject_native_type!()
butpyobject_native_type_core!()
. As such, it cannot be subclassed.Fixing this is not trivial because:
Steps to Reproduce
The following code:
Triggers the error:
Backtrace
No response
Your operating system and version
Windows 11
Your Python version (
python --version
)3.12
Your Rust version (
rustc --version
)rustc 1.80.1 (3f5fd8dd4 2024-08-06)
Your PyO3 version
0.22.0
How did you install python? Did you use a virtualenv?
The official website.
Additional Info
Noticed while working on #4453.
The text was updated successfully, but these errors were encountered: