Skip to content

Commit

Permalink
Fix pg.Dict.sym_hash with child symbolic object which sets `use_sym…
Browse files Browse the repository at this point in the history
…bolic_comparison` to False.

PiperOrigin-RevId: 584486730
  • Loading branch information
daiyip authored and pyglove authors committed Nov 22, 2023
1 parent 3938023 commit 58b60c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyglove/core/symbolic/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def sym_hash(self) -> int:
"""Symbolic hashing."""
return base.sym_hash(
(self.__class__,
tuple([base.sym_hash((k, v)) for k, v in self.sym_items()
tuple([(k, base.sym_hash(v)) for k, v in self.sym_items()
if v != pg_typing.MISSING_VALUE])))

def _sym_getattr( # pytype: disable=signature-mismatch # overriding-parameter-type-checks
Expand Down
6 changes: 6 additions & 0 deletions pyglove/core/symbolic/dict_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,12 @@ def __hash__(self):
self.assertEqual(hash(Dict(x=a)), hash(Dict(x=b)))
self.assertNotEqual(hash(Dict(x=B(1))), hash(Dict(x=B(2))))

class C(pg_object.Object):
x: str
use_symbolic_comparison = False

self.assertEqual(Dict(x=C('abc')).sym_hash(), Dict(x=C('abc')).sym_hash())

def test_sym_parent(self):
sd = Dict(x=dict(a=1), y=[])
self.assertIsNone(sd.sym_parent)
Expand Down

0 comments on commit 58b60c3

Please sign in to comment.