-
Notifications
You must be signed in to change notification settings - Fork 782
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
Automatically implement Python getters and setters for public Rust struct fields #1375
Comments
Currently, the best design I can think of is to check:
This approach has the benefit that existing structs don't mysteriously change behavior, and new plain-old-data structs can be created painlessly without having to annotate every field. Its disadvantage is that this behavior may be slightly confusing to end users: all fields are accessible by default, but if you add a Does someone have an idea to improve upon this design, or is there a better design idea altogether? |
Why does it have to be this implicit? A single new attribute or argument (on the struct, not the members) isn't too much to write, and makes it explicit that accessors are automatically generated. I.e.
or
Bikesheds welcome... |
👍 I am strongly in favour of making this an explicit opt-in; doing things automatically is not very idiomatic in Rust. I think it can be the same attribute as for #1376.
|
In that case, I think |
Note that |
Are there any new on this issue? Any plans to implement |
We did add As for other features associated with "data classes", like constructors, dunder method implementations etc I don't think anyone is working on that. It would be up to someone to come up with a design and an implementation. |
I think one of the main asks for a |
This would make Rust<->Python intercommunication even more seamless. In Rust, you can access struct fields if they are public - why not in Python?
I can't see any problems if PyO3 automatically made Rust struct fields accessible when appropriate, but I'm happy to learn if there are issues I hadn't considered.
The text was updated successfully, but these errors were encountered: