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

request for sample test-cases for python-types -> rust codegen #981

Closed
devdoomari3 opened this issue Jun 16, 2020 · 4 comments
Closed

request for sample test-cases for python-types -> rust codegen #981

devdoomari3 opened this issue Jun 16, 2020 · 4 comments
Labels

Comments

@devdoomari3
Copy link

devdoomari3 commented Jun 16, 2020

Hello!

I made python-codegen to extract function-signatures/etc for code-generation
https://github.com/pycodegen/python-codegen

(python -> typescript example: https://github.com/pycodegen/python-codegen/tree/develop/py_codegen/plugins/typescript )

I'm hoping to use this for generating rust-type definitions from python-files (python -> rust (pyO3) )

Could you give me sample cases so I can make test-cases from those?
(maybe strings / arrays / some unique python quirks to consider / etc)

examples:

this python-function should be converted to

def someFunc(arg1: int) -> int

should converts to:

func someFunc(arg1: int32) -> int32

and this python-function

def someClassFunc(a: SomeClass) -> ...

should be converted to

func someClassFunc(a: &mut SomeClass) -> ... // this requires reading the function body?

and etc

thank you!

ps: this is the opposite of #510 issue

@davidhewitt
Copy link
Member

Hi @devdoomari3, thanks for posting the issue, python-codegen looks like an interesting project.

What you're asking for is pretty open ended, and pyo3 maintainers are short enough on time already so I don't think we'll be likely to write you a list of examples any time soon.

Instead, if you write in this issue any Python examples for which you are unsure what the Rust code should be, I'm happy to discuss possible transformations with you.

For example, your function taking a Rust class:

def someClassFunc(a: SomeClass) -> ...

This should probably be

fn someClassFunc(a: &PyCell<SomeClass>) -> PyResult<...>

And then you could use a.try_borrow()? or a.try_borrow_mut()? to read or write contents of the class.

@devdoomari3
Copy link
Author

devdoomari3 commented Jun 16, 2020

@davidhewitt thanks for the example!

sorry for adding burden on PyO3 🙏
I'm asking this question because I'm a rust newbie (I probably understand only 30~40% of PyO3 docs 😢 )

anyway, this issue isn't urgent (it's just a hobby project for now), but I'm hoping to keep this issue open so some passersby can add comments here

ps:

And then you could use a.try_borrow()? or a.try_borrow_mut()? to read or write contents of the class.

does that mean I have to read body of python-function (def someClassFunc) and check whether a is mutated inside the class? Or it doesn't matter, since that can't be expressed in current PyO3 type system?

@davidhewitt
Copy link
Member

does that mean I have to read body of python-function (def someClassFunc) and check whether a is mutated inside the class?

Ah sorry I misread, you're just generating the definitions, not the function bodies. So PyCell<SomeClass> will always work for you.

@davidhewitt
Copy link
Member

As this issue is a question with no activity for a couple of months, I'm going to close it to keep the issue tracker tidy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants