-
Notifications
You must be signed in to change notification settings - Fork 784
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
Support #[pyfunction]
inside #[pymodule]
#693
Conversation
5737d4f
to
44033ba
Compare
one reason to have separate |
#[pymodule]
fn pyfunction_module(_py: Python, module: &PyModule) -> PyResult<()> {
#[pyfunction]
fn foobar() -> usize {
101
}
Ok(())
} Hmm... 🤔 #[pymodule]
mod pyfunction_module {
#[pyfunction]
fn foobar() -> usize {
101
}
} |
Is there any case where you would write a This PR doesn't change the fact that |
I can add However, my original motivation is that we don't seem to need two differently-named attributes I wasn't planning on changing anything besides making it possible to use |
@kngwyu I see what you mean by automatic adding being confusing. I realise now this PR is probably a breaking change, as this is already valid code, but does not add
I think the solution is instead to add an attribute
It would be possible to write:
Does this seem better? I've also clarified my rationale for doing this at all on #694. |
I mean that few users expect that the generated code uses unrelated local variable
Hmm... 🤔 |
Ok 👍 Let's pull back on this idea for now. I still think it would be worth having just |
It struck me as strange that
#[pyfn]
exists at all when it should be possible to use#[pyfunction]
inside pymodule.This PR adds exactly that. Maybe this is a road to deprecating / removing
#[pyfn]
so as to make the overall API simpler? (Just one#[pyfunction]
attribute instead of two.)TODO: