-
Notifications
You must be signed in to change notification settings - Fork 914
use extract_argument for #[setter] extraction
#3998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Warn on uses of GIL Refs for `#[setter]` function arguments. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Allow extraction of `&Bound` in `#[setter]` methods. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -586,6 +586,8 @@ pub fn impl_py_setter_def( | |
| } | ||
| }; | ||
|
|
||
| // TODO: rework this to make use of `impl_::params::impl_arg_param` which | ||
| // handles all these cases already. | ||
| let extract = if let PropertyType::Function { spec, .. } = &property_type { | ||
| Some(spec) | ||
| } else { | ||
|
|
@@ -609,8 +611,21 @@ pub fn impl_py_setter_def( | |
| }) | ||
| }) | ||
| .unwrap_or_else(|| { | ||
| let (span, name) = match &property_type { | ||
| PropertyType::Descriptor { field, .. } => (field.ty.span(), field.ident.as_ref().map(|i|i.to_string()).unwrap_or_default()), | ||
| PropertyType::Function { spec, .. } => { | ||
| let (_, args) = split_off_python_arg(&spec.signature.arguments); | ||
| (args[0].ty.span(), args[0].name.to_string()) | ||
| } | ||
| }; | ||
|
|
||
| let holder = holders.push_holder(span); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a TODO to rework this to use (Of course, if you're up for it, can also go for the refactoring now 👀)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added, the TODO for now, I think if we refactor this, this should also get rid of the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, it would be a fair bit of rewiring, hopefully with a rewarding payoff at the end! 👍 |
||
| let gil_refs_checker = holders.push_gil_refs_checker(span); | ||
| quote! { | ||
| let _val = #pyo3_path::FromPyObject::extract_bound(_value.into())?; | ||
| let _val = #pyo3_path::impl_::deprecations::inspect_type( | ||
| #pyo3_path::impl_::extract_argument::extract_argument(_value.into(), &mut #holder, #name)?, | ||
| &#gil_refs_checker | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
|
|
@@ -639,8 +654,8 @@ pub fn impl_py_setter_def( | |
| .ok_or_else(|| { | ||
| #pyo3_path::exceptions::PyAttributeError::new_err("can't delete attribute") | ||
| })?; | ||
| #extract | ||
| #init_holders | ||
| #extract | ||
| let result = #setter_impl; | ||
| #check_gil_refs | ||
| #pyo3_path::callback::convert(py, result) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.