-
Notifications
You must be signed in to change notification settings - Fork 18
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
Using pyo3's signature information to generate python's defualt value #135
Conversation
2fb5f34
to
f3b25ad
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.
Hi, thank you for your contribution! We are surprised that we are just planning to work on coexistence of signature and type hints in function arguments, and, alas, your PR include this feature! What a great synchronicity. 😄
We are willing to merge your PR, provided that corner cases in to_string()
-based approach are fixed; please see the review 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.
It seems that some CI are failing. Please apply rustfmt and clippy accordingly.
Also, if you don't have enough time, I can do the rest of the work, either by creating another PR onto your branch, or directly edit your branch. Please feel free to call for help. 👍
Hi @konn, thank you so much for your review & reply! |
Thanks! As pointed out above, please avoid using
👍 |
f3b25ad
to
d0ae534
Compare
Hi @konn , I replace |
Sorry for forgetting the CI check for util.rs, I fixed them. |
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.
Thank you for your swift reaction and detailed tests! I think we are almost done, but please check some additional reviews.
Thanks! I've just edited your branch so that |
That's a great idea and we can have a more elegant formatter function. I finished that. |
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.
Thank you for your change! I am not aware that to_string()
cannot be used for string literals. It seems calling repr()
is more suitable for this kind of conversion and does string escape properly. See suggestions below.
9c450d2
to
41e4f18
Compare
I do a wrong push and I recall that, ignore that :) |
The suggestions are adopted, waitting for your feedback.
#[pyclass]
#[stub_gen_pyclass]
struct A {
#[pyo3(get,set)]
#[stub_gen(default = 2)]
x: usize,
}
impl Default for A {
fn default() -> A {
Self { x: 2 }
}
} Output: class A:
x: int = 2 |
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.
LGTM 👍, thank you for your contributions!
And thank you for your future contributions.
I think you are fine to work on this PR, but there is no particular need for us for time being, it can take some time to be get merged.
It seems duplicate of #96 - if it is different, please let us know.
This seems good to have, but we have to carefully discuss the design of new type of attribute macro. Anyway, you can feel free to open PRs if it is not a duplicate of an existing ones. Thank you again for your contribution! |
Thanks so much for your assistance! I will open PRs once I finish those ideas. |
#135 introduces optional argument rendering for primitive types. This accidentally rejects default argument with non-`PyAny` `IntoPyObject::Target`. This PR fixes it.
Hi everyone,
I want to improve the function signature when pyo3's signature is specified.
Let me use an example to show what did I do, for the following rust function:
Original output
Now
My approach:
For instance, how to infer python's
[1, 2]
from rust'svec![1,2]
?To summary, I use
pyo3::IntoPyObject::into_pyobject
to get the python object converted fromvec![1,2]
, then callto_string
to get the python object's value.More deltails:
std::sync::LazyLock
, see herepyo3-stub-gen
, I merge the signature information into eachArgInfo
, see here