-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
loading fails for typing.Tuple[()] #517
Comments
I can confirm this fails in python 3.8 (at least) with
|
The message in the TypeError says that you should be passing a type, and not an expression (i.e.
Is there a reason you are passing a tuple instance instead of a tuple? This seems like a bug in python. Or it's a weird corner case...
It might be due to some artifact of this also working:
Regardless, if it's a valid way to declare a typed tuple, then it should be supported. |
It might be possible to change our code to work around this for now. However, ideally dill could support this as I see this type of code all over the place. For example: My understanding is the Tuple[()] means an empty tuple whereas Tuple[tuple] has a different meaning. Any clue why it would work in a previous version? |
Yeah, I just found this is indeed intentional. So, definitely needs support. I'll either need to step through the commits or look at the difference in the dill trace to see what changed. Hard to tell from an error thrown on loading. |
Here's what I'm seeing from
So, essentially it didn't serialize correctly. |
The old trace (note it's python 3.6, but that "shouldn't matter"):
and the new trace (in python 3.7):
(i.e. totally handled by So this means, it would need a special case for creation. However, after thinking about it a bit, I'm pretty sure this is a python bug, and the functionality really should be added to |
This might be something that won't get fixed in python, as ... and empty tuple type pickling works on
|
Here's a potential workaround, and to me seems to be a python bug:
So, a function could be added to intercept the
The question then becomes: how does one know if the intent was to pickle a empty tuple type or the weird (and probably erroneous) empty Tuple? I believe that |
Since typing.Tuple is deprecated, I would suggest to preserve the pickling behavior of 3.4 even if it less semantically precise, to have less breaking changes. |
@tvalentyn: with the new |
What do you think about the idea of accepting a patch into the shims module to handle this edge case? |
FYI: I did file an issue with python |
From the
Hmm, so given that information and everything else above, I'm not sure how to best handle this yet. Will need some thought... |
I assumed, perhaps incorrectly, that it would be removed ~soon and if dill users didn't complain about this particular buggy behavior when pickling the deprecated portion of Python semantics, then perhaps it's not worth fixing it, given that the fix introduces issues for some other group of users due to a bug in cpython that's not going to be fixed. that's my take. in a perfect world of course we'd fix the bug everywhere, but looks like that's not going to happen. One option could be, buggy dill behavior only in 3.10+ after the cpython fixes the bug on their side. But perhaps adding such branching to dill would involve unnecessary complexity. |
I ended up adding special handling to serialize two cases of the |
Thank you. Much appreciated. Left some comments. |
Great. Just tried this out with dill at head and it works great. |
How to reproduce:
Run this code with 0.3.4 you will see it pass.
Run in 0.3.5.1 and you will see it fail.
I get the following error in 0.3.5.1
The text was updated successfully, but these errors were encountered: