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

Add tuple and unit struct support for pyclass macro #1504

Merged
merged 3 commits into from Mar 20, 2021
Merged

Add tuple and unit struct support for pyclass macro #1504

merged 3 commits into from Mar 20, 2021

Conversation

messense
Copy link
Member

@messense messense force-pushed the pyclass branch 2 times, most recently from a284b88 to b95bccf Compare March 18, 2021 10:40
@messense messense marked this pull request as ready for review March 18, 2021 10:40
Copy link
Member

@kngwyu kngwyu left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

tests/test_class_basics.rs Outdated Show resolved Hide resolved
tests/test_getter_setter.rs Outdated Show resolved Hide resolved
tests/test_getter_setter.rs Outdated Show resolved Hide resolved
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 implementing this! Changes look good to me, though I have one follow-up thought around #[pyo3(get, set)].

Needs a CHANGELOG entry.

}
_ => unreachable!(),
} else {
bail_spanned!(field.span() => "get/set are not supported on tuple struct field");
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious what the reason for disallowing get/set is? I was thinking that it should be possible, but a name would be required.

e.g. this seems a plausible combination to me:

#[pyclass]
struct PyFoo(
    #[pyo3(get, set, name = "inner", from_py_with = "pytimestamp_to_int")] i32,
);

I'm happy for us to create an issue to leave this for a follow-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was disallowed just to avoid proc-maco panic when user try to use get/set on it. We can certainly add support for it, I think we can do the follow-up after #1507 merged.

Comment on lines +28 to +29
// By default, don't allow creating instances from python.
assert!(typeobj.call((), None).is_err());
Copy link
Member

Choose a reason for hiding this comment

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

👍

@kngwyu
Copy link
Member

kngwyu commented Mar 20, 2021

Thanks!

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.

Wrapping external rust crate
3 participants