From 82220fec48749ecd5ef73adb7885893cf9490b3d Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Thu, 24 Aug 2023 13:06:37 -0500 Subject: [PATCH] get_cache_key: replace sorted() with immutable Map --- pymbolic/mapper/__init__.py | 3 ++- setup.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pymbolic/mapper/__init__.py b/pymbolic/mapper/__init__.py index eddea8de..8721f42b 100644 --- a/pymbolic/mapper/__init__.py +++ b/pymbolic/mapper/__init__.py @@ -23,6 +23,7 @@ from abc import ABC, abstractmethod from typing import Any, Dict import pymbolic.primitives as primitives +import immutables __doc__ = """ Basic dispatch @@ -251,7 +252,7 @@ def get_cache_key(self, expr, *args, **kwargs): # Must add 'type(expr)', to differentiate between python scalar types. # In Python, the following conditions are true: "hash(4) == hash(4.0)" # and "4 == 4.0", but their traversal results cannot be re-used. - return (type(expr), expr, args, tuple(sorted(kwargs.items()))) + return (type(expr), expr, args, immutables.Map(kwargs)) def __call__(self, expr, *args, **kwargs): result = self._cache.get( diff --git a/setup.py b/setup.py index e0d5f35d..fd03f559 100644 --- a/setup.py +++ b/setup.py @@ -38,6 +38,7 @@ python_requires="~=3.8", install_requires=[ "pytools>=2022.1.14", + "immutables", ], extras_require={ "test": ["pytest>=2.3"],