Skip to content

Commit

Permalink
Cache data structure: cannot use ParamSpec components
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Feb 10, 2025
1 parent 90e5263 commit 4ba5f98
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pymbolic/mapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from warnings import warn

from constantdict import constantdict
from typing_extensions import ParamSpec, TypeIs
from typing_extensions import Any, ParamSpec, TypeIs

import pymbolic.primitives as p
from pymbolic.typing import ArithmeticExpression, Expression
Expand Down Expand Up @@ -1506,7 +1506,12 @@ class CSECachingMapperMixin(ABC, Generic[ResultT, P]):
This method deliberately does not support extra arguments in mapper
dispatch, to avoid spurious dependencies of the cache on these arguments.
"""
_cse_cache_dict: dict[tuple[Expression, P.args, P.kwargs], ResultT]
_cse_cache_dict: dict[
# NOTE: "Any" because it isn not possible to use P.args, P.kwargs here.
# https://github.com/python/typing/discussions/1289#discussioncomment-4168040
# No good alternate strategy exists.
tuple[Expression, tuple[Any, ...], constantdict[str, Any]],
ResultT]

def map_common_subexpression(self,
expr: p.CommonSubexpression,
Expand All @@ -1516,7 +1521,7 @@ def map_common_subexpression(self,
except AttributeError:
ccd = self._cse_cache_dict = {}

key: tuple[Expression, P.args, P.kwargs] = (
key: tuple[Expression, tuple[Any, ...], constantdict[str, Any]] = (
expr, args, constantdict(kwargs))
try:
return ccd[key]
Expand Down

0 comments on commit 4ba5f98

Please sign in to comment.