-
Notifications
You must be signed in to change notification settings - Fork 875
Guide: focus on the module way of creating python modules #5430
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
Conversation
706ec52
to
da505bd
Compare
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 improving this! A few thoughts.
guide/src/module.md
Outdated
# Python::attach(|py| { | ||
# use pyo3::wrap_pymodule; | ||
# use pyo3::types::IntoPyDict; | ||
# use pyo3::ffi::c_str; | ||
# let parent_module = wrap_pymodule!(parent_module)(py); | ||
# let ctx = [("parent_module", parent_module)].into_py_dict(py).unwrap(); | ||
# | ||
# py.run(c_str!("assert parent_module.child_module.func() == 'func'"), None, Some(&ctx)).unwrap(); | ||
# }) |
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.
Do we really need to remove the doctest?
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.
Indeed, added back
guide/src/module.md
Outdated
```rust,no_run | ||
# mod declarative_module_module_attr_test { | ||
use pyo3::prelude::*; | ||
You can provide the `submodule` argument to `#[pymodule()]` for modules that are not top-level modules in order for them to properly generate the `#[pyclass]` `module` attribute automatically. |
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.
I think this probably needs to be moved up into the submodules section (and can have a note saying the inline form will do it automatically).
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.
Done
@@ -3,6 +3,7 @@ | |||
You can create a module using `#[pymodule]`: |
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.
We should decide if we prefer the inline or use
-ing form? I note the readme used the inline form, so we should introduce that first maybe? Or maybe introduce both here, just for functions, and then add more detail below?
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.
I have updated the first example to present both ways of exposing a function (each with an inline comment) and kept the dedicated section about inline elements, describing them all
Co-authored-by: David Hewitt <[email protected]>
824d470
to
61478d9
Compare
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, agreed I think that this syntax is straight up better than the #[pymodule]
functions, and fully supersedes it.
So let's start here and maybe deprecate #[pymodule]
functions in a future release (for 0.27 we are now already deprecating #[pyfn]
).
They have been stable for a few releases now