Skip to content

Commit

Permalink
Fix TokenFactory.create_value value caching for unhashable values
Browse files Browse the repository at this point in the history
  • Loading branch information
rbaltrusch committed Jun 23, 2024
1 parent a5d64f7 commit 5108e07
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion natscript/internal/token_.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def create_value(self, value: Hashable) -> tokenvalue.Value:
"""Returns a new Value object if value cannot be found in the value cache,
otherwise returns the existing Value from the cache.
"""
return self._value_cache.get(value, tokenvalue.Value(value))
try:
return self._value_cache.get(value, tokenvalue.Value(value))
except TypeError: # unhashable
return tokenvalue.Value(value)

@staticmethod
def create_iterable_value(value: Iterable[Any]) -> tokenvalue.IterableValue:
Expand Down

0 comments on commit 5108e07

Please sign in to comment.