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
bpo-44676: Add ability to serialise types.Union #27244
Conversation
s = pickle.dumps(alias) | ||
loaded = pickle.loads(s) | ||
self.assertEqual(alias.__args__, loaded.__args__) | ||
self.assertEqual(alias.__parameters__, loaded.__parameters__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are good checks 👍🏻
I'd also put a plain self.assertEqual(alias, loaded)
. At the moment it's redundant with comparing __args__
but this might not be true later, so this will keep future-proof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I added self.assertEqual(alias, loaded)
line to test.
Lib/test/test_types.py
Outdated
): | ||
types.Union.from_args(1) | ||
|
||
alias = types.Union.from_args((int, str, T)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I was a little weirded out by the single argument that is a tuple but looking at actual usage in typing.py
this is the right choice 👍🏻
Using literals like in this test will be a rare occurence because then you can use the regular syntax for the union.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I used from_args
only to test behaviour of this classmethod.
@@ -299,6 +299,24 @@ is_unionable(PyObject *obj) | |||
return 0; | |||
} | |||
|
|||
static int | |||
is_args_unionable(PyObject *args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: this is extracted from L450 below.
@Fidget-Spinner I also cover case when |
# Conflicts: # Lib/test/test_types.py # Objects/unionobject.c
bpo-44676: Add ability to serialize types.Union (pythonGH-27244)
return NULL; | ||
} | ||
|
||
return Py_BuildValue("O(O)", from_args, alias->args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pablogsal and @uriyyo the reference leak is here, we need to decref from_args
. I am submitting a PR now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just catched it as well: #27332
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Fidget-Spinner for looking at it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fidget-Spinner thanks for solving this issue
(cherry picked from commit fe13f0b) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
@uriyyo thanks again for fixing union pickling. I'm doing a manual backport without the reference leak now to keep 3.10 in sync. |
(cherry picked from commit fe13f0b) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
Nevermind it seems that Pablo got to it first :). |
@Fidget-Spinner I just realise that |
|
https://bugs.python.org/issue44676
The text was updated successfully, but these errors were encountered: