Skip to content
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

wrap_x: change macros back to macro_rules! #2363

Merged
merged 1 commit into from
May 14, 2022

Conversation

davidhewitt
Copy link
Member

Marginal cleanup to convert the wrap_pyfunction and wrap_pymodule macros back to macro_rules! macros.

I think it's marginally easier for both readers and maintainers to follow macro_rules! macros in this simple case. Also allows for better doc links.

src/macros.rs Outdated
Comment on lines 123 to 135
#[macro_export]
macro_rules! wrap_pyfunction {
($function:path) => {
&|arg| {
use $function as def;
$crate::impl_::pyfunction::wrap_pyfunction(def::DEF, arg)
}
};
($function:path, $arg:expr) => {{
use $function as def;
$crate::impl_::pyfunction::wrap_pyfunction(def::DEF, $arg)
}};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it is kinda weird that there are two ways to invoke the macro. (I know it did this before, this is somewhat off-topic). AFAIK the first branch is only for use with add_wrapped, right?

I've seen several people get confused by this macro, so if there's a chance to simplify it I'd like to take it. But at least that should be documented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this, but I'd like to avoid making changes to meet these points in this PR... let me try to push an experiment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2367 as the way I hope we eventually can get rid of the wrap macroa for good.

src/macros.rs Outdated
Comment on lines 131 to 133
($function:path, $arg:expr) => {{
use $function as def;
$crate::impl_::pyfunction::wrap_pyfunction(def::DEF, $arg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
($function:path, $arg:expr) => {{
use $function as def;
$crate::impl_::pyfunction::wrap_pyfunction(def::DEF, $arg)
($function:path, $module:expr) => {{
use $function as def;
$crate::impl_::pyfunction::wrap_pyfunction(def::DEF, $module)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will go for module_or_py (because those are the things it can be, IIRC).

@davidhewitt davidhewitt force-pushed the macro_rules_wrap branch 2 times, most recently from 2199315 to cca0e0b Compare May 10, 2022 18:30
@davidhewitt davidhewitt force-pushed the macro_rules_wrap branch 2 times, most recently from 3463942 to 321cbff Compare May 10, 2022 21:14
@davidhewitt
Copy link
Member Author

Hmm this runs into trouble with glob imports because the macro rules are slightly wonky with paths... see rust-lang/rust#48067

@davidhewitt
Copy link
Member Author

davidhewitt commented May 11, 2022

Actually a slight bit of breakage related to glob imports of submodules with the same name as the containing Rust module seems inevitable but perhaps better behaviour overall - see #2366 (comment)

I think this case should be pretty rare so think it's fine to proceed.

Copy link
Member

@mejrs mejrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@davidhewitt davidhewitt merged commit 1215951 into PyO3:main May 14, 2022
@davidhewitt davidhewitt deleted the macro_rules_wrap branch May 14, 2022 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants