From bdaea26f6f539ad9b41b701ba13c0ae28bb153da Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Wed, 14 Nov 2018 13:38:55 +0000 Subject: [PATCH] utils/misc: memoized: fix kwarg IDs Use __get_memo_id() for keyword arguments, rather than stringifying them. The has somewhat lower chance of producing the same identifier for two conceptually unequal objects. --- devlib/utils/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devlib/utils/misc.py b/devlib/utils/misc.py index 208e177..c7ec8f1 100644 --- a/devlib/utils/misc.py +++ b/devlib/utils/misc.py @@ -661,7 +661,7 @@ def memoized(wrapped, instance, args, kwargs): # pylint: disable=unused-argumen def memoize_wrapper(*args, **kwargs): id_string = func_id + ','.join([__get_memo_id(a) for a in args]) - id_string += ','.join('{}={}'.format(k, v) + id_string += ','.join('{}={}'.format(k, __get_memo_id(v)) for k, v in kwargs.items()) if id_string not in __memo_cache: __memo_cache[id_string] = wrapped(*args, **kwargs)