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

fix error with complex enums with many fields #4832

Merged
merged 1 commit into from
Dec 31, 2024
Merged

Conversation

Icxolu
Copy link
Contributor

@Icxolu Icxolu commented Dec 30, 2024

Changes the expansion of __match_args__ for complex enums to not use Rust tuples to lift the limit of 12 fields.

Closes #4827

@Icxolu Icxolu marked this pull request as ready for review December 31, 2024 10:15
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.

Super, many thanks! Happy New Year :)

Comment on lines +1205 to +1210
let spec = FnSpec::parse(
&mut match_args_impl.sig,
&mut match_args_impl.attrs,
Default::default(),
)?;
let variant_match_args = impl_py_class_attribute(variant_cls_type, &spec, ctx)?;
Copy link
Member

Choose a reason for hiding this comment

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

I had an initial feeling that building the syntax tree and then parsing it might be a bit convoluted (we could just construct a FnSpec directly) but maybe this is actually quite elegant because it means the #[classattr] defined above fully defines the final result.

It would have been nice to avoid the fallibility, but I think it's fine on balance.

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 means the #[classattr] defined above fully defines the final result.

This was my motivation for this. I think it's more robust against accidental inconsistencies (now and in the future)

It would have been nice to avoid the fallibility, but I think it's fine on balance.

Yeah, I was a bit sad as well . It should never fail, so we could also expect, but that did not feel much better to me.

Happy New Year to you as well 🎆

@davidhewitt davidhewitt added this pull request to the merge queue Dec 31, 2024
Merged via the queue into PyO3:main with commit 352ab06 Dec 31, 2024
45 of 46 checks passed
@Icxolu Icxolu deleted the fix/4827 branch December 31, 2024 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enum with struct variants can only have 12 fields
2 participants