-
Notifications
You must be signed in to change notification settings - Fork 802
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
Allow inline struct, enum, fn and mod inside of declarative modules #3902
Conversation
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.
Thanks for this follow-up, I am very excited to see this feature coming together after so long!
Open question: do we want to require adding
#[pymodule_export]
to the elements to be exported or do we export automatically all elements with#[pyclass]
,#[pyfunction]
or#[pymodule]
?
Great question! I think automatic is likely to lead to nicer-reading code (a lot less repetition), so I'd prefer that.
If there are reasons users don't want to export they could just move the code outside the module. Or we could add a #[pyo3(no_export)]
option if users really ask for it, but I'm not convinced that's necessary to add right now...
@davidhewitt Thank you for the reviews!
Perfect! Done! |
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.
Fantastic, imo this leads to a beautiful result I've wanted for years! Thanks 🙏
!has_attribute(&item_enum.attrs, "pymodule_export"), | ||
item.span() => "`#[pymodule_export]` may only be used on `use` statements" | ||
); | ||
if has_attribute(&item_enum.attrs, "pyclass") { |
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.
Very nice way to reuse the existing machinery!
newsfragments/3902.added.md
Outdated
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.
Same thing about the changelog entry not being needed here, I'll remove.
This PR lifts restrictions on the content of declarative modules.
It also allows to add
#[pymodule_export]
to:struct
with#[pyclass]
enum
with#[pyclass]
fn
with#[pyfunction]
mod
with#[pymodule]
Open question: do we want to require adding
#[pymodule_export]
to the elements to be exported or do we export automatically all elements with#[pyclass]
,#[pyfunction]
or#[pymodule]
?Example: