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

Move impl From for Py<T> to macros not used in rust-numpy #1228

Merged
merged 1 commit into from
Oct 12, 2020

Conversation

kngwyu
Copy link
Member

@kngwyu kngwyu commented Oct 11, 2020

Implementing this for PyArray is not allowed in older Rust.
Fixes PyO3/rust-numpy#159.

I also remove $(,$type_param: ident)* from macros not used in rust-numpy.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks for debugging this. I 100% agree we should add a fix for this impl From to 0.12.2, as it is broken for anyone using these macros on Rust 1.39.

I also remove $(,$type_param: ident)* from macros not used in rust-numpy.

I can understand why you chose this cleanup. However I think that these macros should all follow the same form without special-casing for rust-numpy. So if we need $type_param for some, I think we should have $type_param for all of them. (See my other longer comment.)

src/types/mod.rs Outdated
}
}
}

impl From<&'_ $name> for $crate::Py<$name> {
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be nice for rust-numpy to have this impl once it is possible, so maybe can we add a FIXME to move this back to pyobject_native_type_named once we bump MSRV to Rust 1.40 or higher?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

src/types/mod.rs Outdated
@@ -27,6 +27,7 @@ pub use self::string::{PyString, PyString as PyUnicode};
pub use self::tuple::PyTuple;
pub use self::typeobject::PyType;

// NOTE: this is used by rust-numpy and takes `$type_param`.
Copy link
Member

Choose a reason for hiding this comment

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

I must confess I am cautious of giving rust-numpy special treatment in the PyO3 codebase. We should definitely always make things possible for rust-numpy to work but I don't think we should be special-casing PyO3 code for rust-numpy. What if someone wants to work on e.g. rust-tensorflow using PyO3 and needs us to make further special cases? Also what if the macros used by rust-numpy change in future - we'd then need to make another PyO3 release to change these macros.

I think it's best if we make sure that PyO3 APIs are flexible enough to support all crates without needing to introduce special rules for a crate to work.

So I think really all of these macros should continue to take $type_param for best consistency.

@kngwyu kngwyu force-pushed the exclude-py-coversion branch from ddb1a4d to f45242f Compare October 12, 2020 05:00
@kngwyu
Copy link
Member Author

kngwyu commented Oct 12, 2020

Thank you for your review!
I'll revert the changes for $type_param.

@davidhewitt
Copy link
Member

Thanks for addressing. I'll merge this now, then rebase + release 0.12.2 tonight.

But why is this in named? I think it's more of a convert thing.

Yeah, I think you're correct. Let's move it there in the future 👍

@davidhewitt davidhewitt merged commit 1749747 into master Oct 12, 2020
@messense messense deleted the exclude-py-coversion branch March 18, 2021 02:23
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.

Compilation Error with Rust 1.39.0
2 participants