From a1bea6025bfff44a2e5433ce24c8e099a92798d6 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 17 Feb 2026 12:43:47 -0600 Subject: [PATCH 1/4] Type make_stringifier --- pymbolic/primitives.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pymbolic/primitives.py b/pymbolic/primitives.py index 1664330..da6fdb8 100644 --- a/pymbolic/primitives.py +++ b/pymbolic/primitives.py @@ -35,6 +35,7 @@ Any, ClassVar, NoReturn, + ParamSpec, Protocol, TypeAlias, cast, @@ -58,12 +59,15 @@ from .typing import ArithmeticExpression, Expression as _Expression, Number, Scalar +P = ParamSpec("P") + if TYPE_CHECKING: from collections.abc import Callable, Iterable, Mapping from _typeshed import DataclassInstance from pymbolic.geometric_algebra import MultiVector + from pymbolic.mapper.stringifier import StringifyMapper def _have_numpy() -> bool: @@ -663,7 +667,9 @@ def __float__(self) -> float: from pymbolic.mapper.evaluator import evaluate_to_float return evaluate_to_float(self) - def make_stringifier(self, originating_stringifier=None): + def make_stringifier(self, + originating_stringifier: StringifyMapper[P] | None = None + ) -> StringifyMapper[P]: """Return a :class:`pymbolic.mapper.Mapper` instance that can be used to generate a human-readable representation of *self*. Usually a subclass of :class:`pymbolic.mapper.stringifier.StringifyMapper`. From cfd0e3de3ee8ec121d76a64552bd1d8a2b3508df Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 17 Feb 2026 12:43:31 -0600 Subject: [PATCH 2/4] GA stringifier: allow ParamSpec --- pymbolic/geometric_algebra/mapper.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pymbolic/geometric_algebra/mapper.py b/pymbolic/geometric_algebra/mapper.py index 070f322..138df5e 100644 --- a/pymbolic/geometric_algebra/mapper.py +++ b/pymbolic/geometric_algebra/mapper.py @@ -144,20 +144,28 @@ def map_derivative_source( return type(expr)(operand, expr.nabla_id) -class StringifyMapper(StringifyMapperBase[[]]): +class StringifyMapper(StringifyMapperBase[P]): AXES: ClassVar[dict[int, str]] = {0: "x", 1: "y", 2: "z"} - def map_nabla(self, expr: gp.Nabla, /, enclosing_prec: int) -> str: + def map_nabla(self, + expr: gp.Nabla, + /, enclosing_prec: int, + *args: P.args, **kwargs: P.kwargs + ) -> str: return f"∇[{expr.nabla_id}]" def map_nabla_component( - self, expr: gp.NablaComponent, /, enclosing_prec: int) -> str: + self, expr: gp.NablaComponent, /, enclosing_prec: int, + *args: P.args, **kwargs: P.kwargs, + ) -> str: axis = self.AXES.get(expr.ambient_axis, expr.ambient_axis) return f"∇{axis}[{expr.nabla_id}]" def map_derivative_source( - self, expr: gp.DerivativeSource, /, enclosing_prec: int) -> str: - operand = self.rec(expr.operand, PREC_NONE) + self, expr: gp.DerivativeSource, /, enclosing_prec: int, + *args: P.args, **kwargs: P.kwargs, + ) -> str: + operand = self.rec(expr.operand, PREC_NONE, *args, **kwargs) return f"D[{expr.nabla_id}]({operand})" From 2c3bdd6e3fc3c9d7d3b972d4c5c1d080e1db6fbc Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 17 Feb 2026 12:43:42 -0600 Subject: [PATCH 3/4] Fix GA stringifier getting --- pymbolic/geometric_algebra/primitives.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pymbolic/geometric_algebra/primitives.py b/pymbolic/geometric_algebra/primitives.py index 1f59966..8e5a17b 100644 --- a/pymbolic/geometric_algebra/primitives.py +++ b/pymbolic/geometric_algebra/primitives.py @@ -27,7 +27,9 @@ # Consider yourself warned. from abc import ABC, abstractmethod -from typing import TYPE_CHECKING, ClassVar, TypeAlias +from typing import TYPE_CHECKING, ClassVar, ParamSpec, TypeAlias + +from typing_extensions import override import pytools.obj_array as obj_array @@ -38,6 +40,7 @@ if TYPE_CHECKING: from collections.abc import Hashable + from pymbolic.mapper.stringifier import StringifyMapper from pymbolic.typing import ( ArithmeticExpression, ArithmeticExpressionContainerTc, @@ -46,6 +49,7 @@ NablaId: TypeAlias = "Hashable" +P = ParamSpec("P") class MultiVectorVariable(Variable): @@ -55,7 +59,10 @@ class MultiVectorVariable(Variable): # {{{ geometric calculus class _GeometricCalculusExpression(ExpressionNode): - def stringifier(self, originating_stringifier=None): + @override + def make_stringifier(self, + originating_stringifier: StringifyMapper[P] | None = None + ) -> StringifyMapper[P]: from pymbolic.geometric_algebra.mapper import StringifyMapper return StringifyMapper() From 77eb54f0a67dd472b7839950d3cbd38f06e7b092 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 17 Feb 2026 12:43:56 -0600 Subject: [PATCH 4/4] Update baseline --- .basedpyright/baseline.json | 58 ------------------------------------- 1 file changed, 58 deletions(-) diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index 30a31c7..779d45e 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -2542,24 +2542,6 @@ } } ], - "./pymbolic/geometric_algebra/primitives.py": [ - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 26, - "endColumn": 49, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 26, - "endColumn": 49, - "lineCount": 1 - } - } - ], "./pymbolic/imperative/instruction.py": [ { "code": "reportUnusedImport", @@ -8455,14 +8437,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 19, - "endColumn": 40, - "lineCount": 1 - } - }, { "code": "reportArgumentType", "range": { @@ -8709,38 +8683,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 31, - "endColumn": 54, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 31, - "endColumn": 54, - "lineCount": 1 - } - }, - { - "code": "reportUnusedParameter", - "range": { - "startColumn": 31, - "endColumn": 54, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 15, - "endColumn": 36, - "lineCount": 1 - } - }, { "code": "reportAny", "range": {