-
Notifications
You must be signed in to change notification settings - Fork 804
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
() to empty tuple conversion is confusing #4896
Comments
Sorry this change bit you. Are you able to share any detail about the patterns where this ended up problematic? We had some discussion of this change in #4041 (comment) and #2316 (comment). I think as maintainers we had all felt We did note the change on the migration guide, but maybe we underestimated impact. Note that with the old |
I have to admit that I don’t really think of Where it started being a problem is that I have runtime objects on the rust side that need mapping to the Python side. Those hold the equivalent of |
FWIW, I agree with Armin. None kind of plays two roles in Python, which are covered by None:: and () in Rust, while the empty Python tuple is seen rarely, and usually as a standin for "empty collection" that is better served by an empty list. |
That's totally fair points, and I'm happy to be wrong here and change this back. I wonder in a world where Rust has variadic generics based on tuples if Let's perhaps let this issue sit for a bit to see if we can get more input for both sides of the reasoning. |
Interesting view point. I have to admit that I still struggle a bit to imagine a case where this is a problem, but I can see this being confusing. Maybe this due to Pythons
For me storing I also can see the other way around also being confusing. Going from a 0-length to a 1-length tuple on the Rust side to None/Tuple on the Python side is also not really obvious. Another take could be to remove the explicit conversion entirely (we also don't implement Of course everything about this can be worked around by just defining your own ZST with a custom |
Can you explain this more? It makes sense to use
Not sure what you mean here either?
But that's not what we want to ask people to do, is it? |
This was more targeted to the argument being read from some data structure. I agree that using
0-length tuples are valid values in both Python and Rust. I think it can also be confusing if the converted type changes by just changing the length, for example during refactoring. Maybe it's not a big deal, but at least I would not expect that.
I'd say it's the recommended way for custom conversations. Whether we should change it in PyO3 depends on the number of people that feel like it should be changed IMO. |
I just managed to upgrade to the latest PyO3 and I was immediately bitten by the new
()
to empty tuple conversion. I was especially confused because there is a special case now that#[pyfunction]
does actually still perform the old conversion, butinto_py_any
and friends do not.I'm not sure what the motivation of this change was, but I now need to manually handle that case in a few places. Is there ever a situation where you want to treat
()
as an empty tuple?The text was updated successfully, but these errors were encountered: