Skip to content

Commit

Permalink
Merge pull request jupyter-widgets#1523 from jasongrout/json
Browse files Browse the repository at this point in the history
Comparing the json representation should handle idiosyncracies of python->json datastructures
  • Loading branch information
jasongrout authored Jul 19, 2017
2 parents 4ffa003 + 51102f7 commit f688a4f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Undefined)
from ipython_genutils.py3compat import string_types, PY3
from IPython.display import display
from json import loads as jsonloads, dumps as jsondumps

from base64 import standard_b64decode, standard_b64encode

Expand Down Expand Up @@ -595,8 +596,11 @@ def hold_sync(self):
def _should_send_property(self, key, value):
"""Check the property lock (property_lock)"""
to_json = self.trait_metadata(key, 'to_json', self._trait_to_json)
# A roundtrip conversion through json in the comparison takes care of
# idiosyncracies of how python data structures map to json, for example
# tuples get converted to lists.
if (key in self._property_lock
and to_json(value, self) == self._property_lock[key]):
and jsonloads(jsondumps(to_json(value, self))) == self._property_lock[key]):
return False
elif self._holding_sync:
self._states_to_send.add(key)
Expand Down

0 comments on commit f688a4f

Please sign in to comment.