-
Notifications
You must be signed in to change notification settings - Fork 770
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
update extract_argument
to use Bound APIs
#3708
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1301ee1
update `extract_argument` to use `Bound` APIs
davidhewitt 7cb8e99
tidy up borrow in macros expression
davidhewitt 2d07582
update `trybuild` output
davidhewitt 9a599c3
more concise form for `DowncastError::new`
davidhewitt 6badf8e
Merge branch 'main' into extract-arg2
davidhewitt 22f960f
use `Borrowed` instead of newtype
davidhewitt 89913e8
use `Borrowed::from_ptr` methods in extract_argument
davidhewitt 56260a8
Merge branch 'main' into extract-arg2
davidhewitt 9ec7084
update UI tests
davidhewitt 306aa81
avoid double-negative `#[cfg]` clauses
davidhewitt 108f1e7
Merge branch 'main' into extract-arg2
davidhewitt 101563c
review: LilyFoote, Icxolu feedback
davidhewitt 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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -4,62 +4,66 @@ use pyo3::types::{PyDict, PyTuple}; | |
#[pyfunction(signature = ())] | ||
fn none() {} | ||
|
||
type Any<'py> = Bound<'py, PyAny>; | ||
type Dict<'py> = Bound<'py, PyDict>; | ||
type Tuple<'py> = Bound<'py, PyTuple>; | ||
Comment on lines
+7
to
+9
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. Clippy was warning about type complexity in the return value tuples without defining these aliases. |
||
|
||
#[pyfunction(signature = (a, b = None, *, c = None))] | ||
fn simple<'a>( | ||
a: &'a PyAny, | ||
b: Option<&'a PyAny>, | ||
c: Option<&'a PyAny>, | ||
) -> (&'a PyAny, Option<&'a PyAny>, Option<&'a PyAny>) { | ||
fn simple<'py>( | ||
a: Any<'py>, | ||
b: Option<Any<'py>>, | ||
c: Option<Any<'py>>, | ||
) -> (Any<'py>, Option<Any<'py>>, Option<Any<'py>>) { | ||
(a, b, c) | ||
} | ||
|
||
#[pyfunction(signature = (a, b = None, *args, c = None))] | ||
fn simple_args<'a>( | ||
a: &'a PyAny, | ||
b: Option<&'a PyAny>, | ||
args: &'a PyTuple, | ||
c: Option<&'a PyAny>, | ||
) -> (&'a PyAny, Option<&'a PyAny>, &'a PyTuple, Option<&'a PyAny>) { | ||
fn simple_args<'py>( | ||
a: Any<'py>, | ||
b: Option<Any<'py>>, | ||
args: Tuple<'py>, | ||
c: Option<Any<'py>>, | ||
) -> (Any<'py>, Option<Any<'py>>, Tuple<'py>, Option<Any<'py>>) { | ||
(a, b, args, c) | ||
} | ||
|
||
#[pyfunction(signature = (a, b = None, c = None, **kwargs))] | ||
fn simple_kwargs<'a>( | ||
a: &'a PyAny, | ||
b: Option<&'a PyAny>, | ||
c: Option<&'a PyAny>, | ||
kwargs: Option<&'a PyDict>, | ||
fn simple_kwargs<'py>( | ||
a: Any<'py>, | ||
b: Option<Any<'py>>, | ||
c: Option<Any<'py>>, | ||
kwargs: Option<Dict<'py>>, | ||
) -> ( | ||
&'a PyAny, | ||
Option<&'a PyAny>, | ||
Option<&'a PyAny>, | ||
Option<&'a PyDict>, | ||
Any<'py>, | ||
Option<Any<'py>>, | ||
Option<Any<'py>>, | ||
Option<Dict<'py>>, | ||
) { | ||
(a, b, c, kwargs) | ||
} | ||
|
||
#[pyfunction(signature = (a, b = None, *args, c = None, **kwargs))] | ||
fn simple_args_kwargs<'a>( | ||
a: &'a PyAny, | ||
b: Option<&'a PyAny>, | ||
args: &'a PyTuple, | ||
c: Option<&'a PyAny>, | ||
kwargs: Option<&'a PyDict>, | ||
fn simple_args_kwargs<'py>( | ||
a: Any<'py>, | ||
b: Option<Any<'py>>, | ||
args: Tuple<'py>, | ||
c: Option<Any<'py>>, | ||
kwargs: Option<Dict<'py>>, | ||
) -> ( | ||
&'a PyAny, | ||
Option<&'a PyAny>, | ||
&'a PyTuple, | ||
Option<&'a PyAny>, | ||
Option<&'a PyDict>, | ||
Any<'py>, | ||
Option<Any<'py>>, | ||
Tuple<'py>, | ||
Option<Any<'py>>, | ||
Option<Dict<'py>>, | ||
) { | ||
(a, b, args, c, kwargs) | ||
} | ||
|
||
#[pyfunction(signature = (*args, **kwargs))] | ||
fn args_kwargs<'a>( | ||
args: &'a PyTuple, | ||
kwargs: Option<&'a PyDict>, | ||
) -> (&'a PyTuple, Option<&'a PyDict>) { | ||
fn args_kwargs<'py>( | ||
args: Tuple<'py>, | ||
kwargs: Option<Dict<'py>>, | ||
) -> (Tuple<'py>, Option<Dict<'py>>) { | ||
(args, kwargs) | ||
} | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
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.
These changes to return
result
on a separate line were caused by the fact that#call
creates a borrow on_args
and_kwargs
, which now haveDrop
implementations due to beingBound<PyTuple>
andOption<Bound<PyDict>>
(if*args
, or**kwargs
are accepted).So to satisfy the borrow checker we had to split the expression like this.
I think given our decision in macro code is to trend away from a single giant expression anyway, and it'll help me in #3847 where I need to do this too, this seemed a reasonable adjustment to me.