Skip to content

fix error with complex enums with many fields#4832

Merged
davidhewitt merged 1 commit intoPyO3:mainfrom
Icxolu:fix/4827
Dec 31, 2024
Merged

fix error with complex enums with many fields#4832
davidhewitt merged 1 commit intoPyO3:mainfrom
Icxolu:fix/4827

Conversation

@Icxolu
Copy link
Copy Markdown
Member

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member 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
@Icxolu Icxolu deleted the fix/4827 branch December 31, 2024 23:56
JeanArhancet pushed a commit to JeanArhancet/pyo3 that referenced this pull request Jan 17, 2025
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