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

refactor #[setter] argument extraction #4002

Merged
merged 1 commit into from
Apr 1, 2024

Conversation

Icxolu
Copy link
Contributor

@Icxolu Icxolu commented Mar 27, 2024

I took a shot at the refactoring of the #[setter] argument discussed in #3998 (comment).

This tries to decouples impl_arg_param from the layout used in regular #[pyfunction]/#[pymethods] by moving the args_array assumption one layer up. I left PropertyType::Descriptor untouched because I don't see a good may to integrate that (but since that one is not customizable it seem fine)

The deprecation warning make this still quite noisy, but I think once we can finally (🙏 ) remove them, this should get significantly better.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! I think even if this is a net increase in code size right now, I'm optimistic that it'll get much nicer once the migration is complete, as you say.

Is there a particular reason why you kept this in draft? Otherwise I would be happy so see this merged already and then further refactoring can be done later.

Comment on lines +67 to +69
pub fn is_regular(&self) -> bool {
!self.py && !self.is_cancel_handle && !self.is_kwargs && !self.is_varargs
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this I'm thinking FnArg might want to be reworked to be an enum. Not sure if it's worth trying to make that part of this PR or we punt for another time.

Comment on lines +177 to +179
if arg.is_regular() {
option_pos += 1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little unfortunate to have the coupling between incrementing the option and impl_arg_param. I guess that having the enum, then impl_arg_param could be used just for "Regular" variants and then other args like py or cancel_handle could be their own branches.

Maybe it's better for me to try to implement what I mean than add a drive by comment for that, though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to continue/add something here if you have something in mind. I wasn't really satisfied by how this turned out either (which is why I left it as draft for now)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, I'll try to find a good moment to do this soon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have played around a bit with your enum idea over here. Maybe that goes into the direction that you hand in mind? That does definetly decouple the different branches from each other, but it's a bit more involved and not really relevant to the #[setter] rework here. So maybe you are right to leave this as is, and rework FnArg in a followup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That definitely looks like the idea I had in mind. Does it feel like a step in the right direction as you're working on it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does feel nicer in my opinion. Having an enum over a bunch of booleans not only makes it much clearer what the branches are, but also make a lot of weird combinations (like optional py/varargs, required kwargs, ...) unrepresentable, which is always good. This also moves the error checking of those cases to construction/parsing side instead of usage side, which for me feels a more appropriate place for them. In some places the matching is bit more verbose, but maybe there could be some helper methods for those (or maybe its even fine like it is)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! In which case let's merge this one now so that it's possible to start reviewing the follow up :)

@davidhewitt davidhewitt marked this pull request as ready for review April 1, 2024 12:10
@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Apr 1, 2024
@davidhewitt davidhewitt added this pull request to the merge queue Apr 1, 2024
Merged via the queue into PyO3:main with commit 8f87b86 Apr 1, 2024
40 of 42 checks passed
@Icxolu Icxolu deleted the refactor-setter branch April 1, 2024 18:04
@Icxolu Icxolu mentioned this pull request Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-skip-changelog Skip checking changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants