From a2ecb3c981e71da96d2d8beca98cf3101475eb5c Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 3 Feb 2025 16:42:57 -0600 Subject: [PATCH] Switch to constantdict --- doc/conf.py | 4 ++-- pymbolic/mapper/__init__.py | 8 ++++---- pymbolic/parser.py | 4 ++-- pymbolic/primitives.py | 9 ++++----- pyproject.toml | 2 +- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index ba52921..4de303d 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -24,8 +24,8 @@ "sympy": ("https://docs.sympy.org/dev/", None), "typing_extensions": ("https://typing-extensions.readthedocs.io/en/latest/", None), - "immutabledict": - ("https://immutabledict.corenting.fr/", None) + "constantdict": + ("https://matthiasdiener.github.io/constantdict/", None) } autodoc_type_aliases = { "Expression": "Expression", diff --git a/pymbolic/mapper/__init__.py b/pymbolic/mapper/__init__.py index f0d060e..9e98108 100644 --- a/pymbolic/mapper/__init__.py +++ b/pymbolic/mapper/__init__.py @@ -35,7 +35,7 @@ ) from warnings import warn -from immutabledict import immutabledict +from constantdict import constantdict from typing_extensions import ParamSpec, TypeIs import pymbolic.primitives as p @@ -413,7 +413,7 @@ def get_cache_key(self, # 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, immutabledict(kwargs)) + return (type(expr), expr, args, constantdict(kwargs)) def __call__(self, expr: Expression, @@ -760,7 +760,7 @@ def map_call_with_kwargs(self, parameters = tuple([ self.rec(child, *args, **kwargs) for child in expr.parameters ]) - kw_parameters: Mapping[str, Expression] = immutabledict({ + kw_parameters: Mapping[str, Expression] = constantdict({ key: self.rec(val, *args, **kwargs) for key, val in expr.kw_parameters.items()}) @@ -1517,7 +1517,7 @@ def map_common_subexpression(self, ccd = self._cse_cache_dict = {} key: tuple[Expression, P.args, P.kwargs] = ( - expr, args, immutabledict(kwargs)) + expr, args, constantdict(kwargs)) try: return ccd[key] except KeyError: diff --git a/pymbolic/parser.py b/pymbolic/parser.py index f1d0824..b045677 100644 --- a/pymbolic/parser.py +++ b/pymbolic/parser.py @@ -27,7 +27,7 @@ from sys import intern from typing import TYPE_CHECKING, ClassVar, TypeAlias -from immutabledict import immutabledict +from constantdict import constantdict import pytools.lex from pytools import memoize_method @@ -348,7 +348,7 @@ def parse_postfix(self, pstate, min_precedence, left_exp): if kwargs: left_exp = primitives.CallWithKwargs( - left_exp, args, immutabledict(kwargs)) + left_exp, args, constantdict(kwargs)) else: left_exp = primitives.Call(left_exp, args) diff --git a/pymbolic/primitives.py b/pymbolic/primitives.py index babe00d..9f6c1db 100644 --- a/pymbolic/primitives.py +++ b/pymbolic/primitives.py @@ -39,7 +39,7 @@ ) from warnings import warn -from immutabledict import immutabledict +from constantdict import constantdict from typing_extensions import TypeIs, dataclass_transform from pytools import module_getattr_for_deprecations @@ -621,8 +621,7 @@ def __pos__(self) -> ArithmeticExpression: def __call__(self, *args, **kwargs) -> Call | CallWithKwargs: if kwargs: - from immutabledict import immutabledict - return CallWithKwargs(self, args, immutabledict(kwargs)) + return CallWithKwargs(self, args, constantdict(kwargs)) else: return Call(self, args) @@ -1216,10 +1215,10 @@ def __post_init__(self): warn("CallWithKwargs created with non-hashable kw_parameters. " "This is deprecated and will stop working in 2025. " "If you need an immutable mapping, " - "try the :mod:`immutabledict` package.", + "try the :mod:`constantdict` package.", DeprecationWarning, stacklevel=3 ) - object.__setattr__(self, "kw_parameters", immutabledict(self.kw_parameters)) + object.__setattr__(self, "kw_parameters", constantdict(self.kw_parameters)) @expr_dataclass() diff --git a/pyproject.toml b/pyproject.toml index e35d6a1..950ed34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ classifiers = [ "Topic :: Utilities", ] dependencies = [ - "immutabledict", + "constantdict", "pytools>=2024.1.16", # for dataclass_transform, TypeAlias, deprecated "typing-extensions>=4.5",