Skip to content

Commit 00baa48

Browse files
committed
reuse hashing
1 parent cb84367 commit 00baa48

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

dash/_utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,24 @@ def create_callback_id(output, inputs, no_output=False):
137137
# with `\` so we don't mistake it for multi-outputs
138138
hashed_inputs = None
139139

140+
def _hash_inputs():
141+
return hashlib.sha256(
142+
".".join(str(x) for x in inputs).encode("utf-8")
143+
).hexdigest()
144+
140145
def _concat(x):
141146
nonlocal hashed_inputs
142147
_id = x.component_id_str().replace(".", "\\.") + "." + x.component_property
143148
if x.allow_duplicate:
144149
if not hashed_inputs:
145-
hashed_inputs = hashlib.sha256(
146-
".".join(str(x) for x in inputs).encode("utf-8")
147-
).hexdigest()
150+
hashed_inputs = _hash_inputs
148151
# Actually adds on the property part.
149152
_id += f"@{hashed_inputs}"
150153
return _id
151154

152155
if no_output:
153156
# No output will hash the inputs.
154-
return hashlib.sha256(
155-
".".join(str(x) for x in inputs).encode("utf-8")
156-
).hexdigest()
157+
return _hash_inputs
157158

158159
if isinstance(output, (list, tuple)):
159160
return ".." + "...".join(_concat(x) for x in output) + ".."

0 commit comments

Comments
 (0)