robertwb commented on code in PR #34414:
URL: https://github.com/apache/beam/pull/34414#discussion_r2012884703
##########
sdks/python/apache_beam/typehints/typehints.py:
##########
@@ -505,7 +505,11 @@ class UnionHint(CompositeTypeHint):
"""
class UnionConstraint(TypeConstraint):
def __init__(self, union_types):
- self.union_types = set(normalize(t) for t in union_types)
+ # Use a list instead of a set to make the pickle serialization
+ # deterministic.
+ self.union_types = list(set(normalize(t) for t in union_types))
+ # Sorting the type name strings simplifies unit tests.
+ self.union_types.sort(key=repr)
def __eq__(self, other):
Review Comment:
Suppose we have two type hints such that `x == y` but `repr(x) != repr(y)`.
(This is not as uncommon as one might think, as `repr(x)` by default includes
the address of `x` but not any of its internal structure.) In that case, one
might have `sorted([x, z], key=repr)) != sorted([z, y], key=repr)` despite
`set([x,z]) == set([z,y])`. So the comparison must be done on the
`self.union_types` and `other.union_types` as sets, not as lists.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]