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

Class module name default #1820

Closed
aviramha opened this issue Aug 21, 2021 · 8 comments
Closed

Class module name default #1820

aviramha opened this issue Aug 21, 2021 · 8 comments

Comments

@aviramha
Copy link
Member

Hi,
I'm deeply annoyed by the fact that if you declare a module using the #[pyclass] macro the module name of the class is builtins.
I looked in the code and I understand why it's a bit problematic.
At first I thought adding the module name to PyTypeInfo::type_object_raw then it could propagate to the class definition where it can use the module name.
I assume that's a bad practice as it's not part of the creation really..
Another thought I had in mind is to create a trait for get_module_name with a default implementation, then have a macro for adding a class into a module where it impls the trait.

Any feedback is welcome :)

@davidhewitt
Copy link
Member

I agree that builtins is very annoying. You can use #[pyclass(module = "xyz")] to override this.

Also, I was thinking that with the future module syntax proposed in #694 (comment) it should become easy for us to automatically set the correct module name for the pyclass.

@aviramha
Copy link
Member Author

Yes I am aware of the #[pyclass(module =..)] feature
The syntax proposal looks good. Could it be a milestone for 0.15?

@davidhewitt
Copy link
Member

I would really like to introduce it as part of 0.15, yes. I'd love to build it myself eventually, however if anyone's interested in picking it up it'd be a very welcome addition!

The way I was thinking of introducing it was that we'd continue to accept the existing #[pymodule] syntax for now; this would be a new code path which triggers when putting #[pymodule] on top of a Rust module.

@aganders3
Copy link
Contributor

Is this possibly a good “first timer” contribution? I’d love to get involved in this project but am a relative beginner in Rust and don’t want to bite off more than I can chew.

@davidhewitt
Copy link
Member

Sorry for my slightly slow reply - I see you have started looking into the CI test failures, which is really appreciated. This issue is not the easiest, because the new #[pymodule] syntax will have a lot of design complexity and involve a lot of new proc macro code. If you're not afraid to dive in then I can offer some mentoring!

Alternatively I can try to mark some issues with a label which suggests what's good to start with?

@aganders3
Copy link
Contributor

No worries! Thanks for the thoughtful response.

I'm not afraid to dive in but must admit I don't have experience with proc macros (yet) so I'm probably not the most efficient person to implement this. If there are better places to start I'd love some direction if/when you can find some time to label them. In the meantime I will keep an eye on the issues and just keep trying to familiarize myself with the code a bit more.

@davidhewitt davidhewitt modified the milestones: 0.15, 0.16 Nov 12, 2021
@davidhewitt davidhewitt modified the milestones: 0.16, 0.17 Feb 26, 2022
@davidhewitt davidhewitt modified the milestones: 0.17, 0.18 Jul 3, 2022
@davidhewitt davidhewitt modified the milestones: 0.18, 0.19 Dec 27, 2022
@davidhewitt
Copy link
Member

For anyone looking, I began drafting an implementation in #2367 but haven't had time to finish it off. I do hope to get it over the line before too much more time passes!

@davidhewitt davidhewitt removed this from the 0.19 milestone Jun 16, 2023
@davidhewitt
Copy link
Member

Closing, will track this as part of #3900

@davidhewitt davidhewitt closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants