-
Notifications
You must be signed in to change notification settings - Fork 784
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
Enum with struct variants can only have 12 fields #4827
Comments
Hi @MartinJepsen! Unfortunately, this is caused by a limitation of Rust itself. Specifically, Rust does not support Variadic Generics, so we follow the Rust standard library pattern of supporting up to length 12 tuples. See also https://gist.github.com/PoignardAzur/aea33f28e2c58ffe1a93b8f8d3c58667. Can I ask why you want to refactor away from the wrapped types? That seems to me a better pattern than expanding the support in PyO3 to longer tuples. |
I agree that adding support for larger tuples is not a helpful. However the fundamental problem seems to be caused merely by our expansion for pyo3/pyo3-macros-backend/src/pyclass.rs Lines 1198 to 1201 in 3965f5f
which expands to something like #[classattr]
const __match_args__: (&str, ..., &str) = ("field_1", ..., "field_15"); in this case, which relies on the #[classattr]
fn __match_args__(py: Python<'_>) -> PyResult<Bound<'_, PyTuple>> {
PyTuple::new(py, ["field_1", ..., "field_15"])
} I prototyped this in #4832 |
I just thought it looked a bit cleaner. I'm basically deserializing the structs from binary data, so instead of implementing a I don't expect support for longer tuples. If it's a limitation of Rust, then that's completely fine and not something pyo3 should solve. I was mostly wondering about the reason for this behaviour. Thank you for the explanation! |
Bug Description
I was refactoring some code from
to this
Effectively getting rid of the wrapped types and representing them in the enum's variants directly.
However, it looks like there is some kind of limit on the number of fields that you can have in an enum member. The example in the "Steps to reproduce" produces this error:
Steps to Reproduce
won't compile. However, with 12 fields, there is no error:
Backtrace
Your operating system and version
Ubuntu 24.04
Your Python version (
python --version
)Python 3.12.3
Your Rust version (
rustc --version
)rustc 1.83.0 (90b35a623 2024-11-26)
Your PyO3 version
0.23.3
How did you install python? Did you use a virtualenv?
No venv, just the
python3
that comes with Ubuntu 24.04.Additional Info
Thanks for this awesome project. I imagine creating this is an insane task. So lots of appreciation from here :)
The text was updated successfully, but these errors were encountered: