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
Firstly, thank you for creating this amazing crate!
I noticed today that when using #[new] to generate a __new__ method with an empty signature, the generated code doesn't enforce that _args and _kwargs must be empty. As a result, it's possible to call the constructor from Python and provide unused arguments without raising an exception. This could be confusing, for example the developer might expect the kwargs to set field values. I think this is a bug.
Here's part of the code generated by the macros, from cargo expand:
impl Foo {
unsafe extern "C" fn __pymethod___new____(
subtype: *mut _pyo3::ffi::PyTypeObject,
_args: *mut _pyo3::ffi::PyObject,
_kwargs: *mut _pyo3::ffi::PyObject,
) -> *mut _pyo3::ffi::PyObject {
use _pyo3::{callback::IntoPyCallbackOutput, pyclass_init::PyObjectInit};
let gil = _pyo3::GILPool::new();
let _py = gil.python();
_pyo3::callback::panic_result_into_callback_output(
_py,
::std::panic::catch_unwind(move || -> _pyo3::PyResult<_> {
let result = Foo::new();
let initializer: _pyo3::PyClassInitializer<Foo> = result.convert(_py)?;
initializer.into_new_object(_py, subtype)
}),
)
}
}
This code prints three objects, without raising any exceptions. The expected behavior would be to print the first and raise an exception on the second (and third of course).
Backtrace
No response
Your operating system and version
WSL2
Your Python version (python --version)
3.11.0
Your Rust version (rustc --version)
rustc 1.60.0-nightly (22e491ac7 2022-01-13)
Your PyO3 version
0.17.3
How did you install python? Did you use a virtualenv?
venv
Additional Info
No response
The text was updated successfully, but these errors were encountered:
Bug Description
Firstly, thank you for creating this amazing crate!
I noticed today that when using
#[new]
to generate a__new__
method with an empty signature, the generated code doesn't enforce that _args and _kwargs must be empty. As a result, it's possible to call the constructor from Python and provide unused arguments without raising an exception. This could be confusing, for example the developer might expect the kwargs to set field values. I think this is a bug.Here's part of the code generated by the macros, from
cargo expand
:Steps to Reproduce
This code prints three objects, without raising any exceptions. The expected behavior would be to print the first and raise an exception on the second (and third of course).
Backtrace
No response
Your operating system and version
WSL2
Your Python version (
python --version
)3.11.0
Your Rust version (
rustc --version
)rustc 1.60.0-nightly (22e491ac7 2022-01-13)
Your PyO3 version
0.17.3
How did you install python? Did you use a virtualenv?
venv
Additional Info
No response
The text was updated successfully, but these errors were encountered: