-
Notifications
You must be signed in to change notification settings - Fork 782
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
deprecate &PyModule
as #[pymodule]
argument type
#3936
Merged
+126
−10
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1cfba4d
deprecate `&PyModule` as `#[pymodule]` argument type
Icxolu 34acc50
cleanup
Icxolu 0d3e76f
add ui tests
Icxolu d48e1ee
fix deprecations in tests
Icxolu b2009ea
fix maturin and setuptools-rust starters
Icxolu a85157e
run `deprecated` ui test only when `gil-refs` as disabled
Icxolu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Loading status checks…
deprecate
&PyModule
as #[pymodule]
argument type
commit 1cfba4d4cc88bc861de53f0c3c645f5c9eb7198d
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ use crate::{ | |
pyfunction::{impl_wrap_pyfunction, PyFunctionOptions}, | ||
}; | ||
use proc_macro2::TokenStream; | ||
use quote::quote; | ||
use quote::{quote, quote_spanned}; | ||
use syn::{ | ||
ext::IdentExt, | ||
parse::{Parse, ParseStream}, | ||
|
@@ -295,8 +295,29 @@ pub fn pymodule_function_impl(mut function: syn::ItemFn) -> Result<TokenStream> | |
} | ||
module_args.push(quote!(::std::convert::Into::into(BoundRef(module)))); | ||
|
||
let syn::ItemFn { | ||
attrs, sig, block, .. | ||
} = &function; | ||
|
||
let extractors = sig.inputs.iter().filter_map(|param| { | ||
if let syn::FnArg::Typed(pat_type) = param { | ||
if let syn::Pat::Ident(pat_ident) = &*pat_type.pat { | ||
let ident = &pat_ident.ident; | ||
return Some(quote_spanned! { pat_type.span() => { | ||
let (_, e) = #pyo3_path::impl_::pymethods::inspect_type(#ident); | ||
let _ = e.extract_gil_ref(); | ||
}}); | ||
} | ||
} | ||
None | ||
}); | ||
|
||
Ok(quote! { | ||
#function | ||
#(#attrs)* | ||
#vis #sig { | ||
#(#extractors)* | ||
#block | ||
} | ||
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. Rather than splitting up the function it might be possible to insert these into the front of |
||
#vis mod #ident { | ||
#initialization | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might need to assign the argument back out:
(I think this would matter for edge cases where the module is using
Bound<'_, PyModule>
orPy<PyModule>
for some reason, andinspect_type
would transfer ownership rather than copy.)