Skip to content

Commit ce6dc1e

Browse files
committed
Rename type aliases for consistency
1 parent 2c78743 commit ce6dc1e

27 files changed

+448
-360
lines changed

doc/conf.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@
2828
("https://immutabledict.corenting.fr/", None)
2929
}
3030
autodoc_type_aliases = {
31-
"ExpressionT": "ExpressionT",
32-
"ArithmeticExpressionT": "ArithmeticExpressionT",
31+
"Expression": "Expression",
32+
"ArithmeticExpression": "ArithmeticExpression",
3333
}
3434

35+
36+
nitpick_ignore_regex = [
37+
# Avoids this error. Not sure where to even look.
38+
# <unknown>:1: WARNING: py:class reference target not found: ExpressionNode [ref.class] # noqa: E501
39+
["py:class", r"ExpressionNode"],
40+
]
41+
42+
3543
import sys
3644

3745

doc/index.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ You can also easily define your own objects to use inside an expression:
6969

7070
.. doctest::
7171

72-
>>> from pymbolic.primitives import Expression, expr_dataclass
72+
>>> from pymbolic import ExpressionNode, expr_dataclass
73+
>>> from pymbolic.typing import Expression
7374
>>>
7475
>>> @expr_dataclass()
75-
... class FancyOperator(Expression):
76+
... class FancyOperator(ExpressionNode):
7677
... operand: Expression
7778
...
7879
>>> u

doc/utilities.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Parser
88

99
.. function:: parse(expr_str)
1010

11-
Return a :class:`pymbolic.primitives.Expression` tree corresponding to *expr_str*.
11+
Return a :class:`pymbolic.primitives.ExpressionNode` tree corresponding
12+
to *expr_str*.
1213

1314
The parser is also relatively easy to extend. See the source code of the following
1415
class.

pymbolic/__init__.py

+49-36
Original file line numberDiff line numberDiff line change
@@ -24,54 +24,60 @@
2424
"""
2525

2626

27-
from pymbolic.version import VERSION_TEXT as __version__ # noqa
28-
29-
from . import parser
30-
from . import compiler
27+
from functools import partial
3128

32-
from .mapper import evaluator
33-
from .mapper import stringifier
34-
from .mapper import dependency
35-
from .mapper import substitutor
36-
from .mapper import differentiator
37-
from .mapper import distributor
38-
from .mapper import flattener
39-
from . import primitives
29+
from pytools import module_getattr_for_deprecations
4030

41-
from .primitives import (Variable as var, # noqa: N813
31+
from . import compiler, parser, primitives
32+
from .compiler import compile
33+
from .mapper import (
34+
dependency,
35+
differentiator,
36+
distributor,
37+
evaluator,
38+
flattener,
39+
stringifier,
40+
substitutor,
41+
)
42+
from .mapper.differentiator import differentiate, differentiate as diff
43+
from .mapper.distributor import distribute, distribute as expand
44+
from .mapper.evaluator import evaluate, evaluate_kw
45+
from .mapper.flattener import flatten
46+
from .mapper.substitutor import substitute
47+
from .parser import parse
48+
from .primitives import ( # noqa: N813
49+
ExpressionNode,
4250
Variable,
43-
Expression,
44-
variables,
45-
flattened_sum,
46-
subscript,
51+
Variable as var,
52+
disable_subscript_by_getitem,
53+
expr_dataclass,
4754
flattened_product,
48-
quotient,
55+
flattened_sum,
4956
linear_combination,
5057
make_common_subexpression as cse,
5158
make_sym_vector,
52-
disable_subscript_by_getitem,
53-
expr_dataclass,
59+
quotient,
60+
subscript,
61+
variables,
5462
)
55-
from .parser import parse
56-
from .mapper.evaluator import evaluate
57-
from .mapper.evaluator import evaluate_kw
58-
from .compiler import compile
59-
from .mapper.substitutor import substitute
60-
from .mapper.differentiator import differentiate as diff
61-
from .mapper.differentiator import differentiate
62-
from .mapper.distributor import distribute as expand
63-
from .mapper.distributor import distribute
64-
from .mapper.flattener import flatten
65-
from .typing import NumberT, ScalarT, ArithmeticExpressionT, ExpressionT, BoolT
63+
from .typing import (
64+
ArithmeticExpression,
65+
Bool,
66+
Expression,
67+
Expression as _TypingExpression,
68+
Number,
69+
Scalar,
70+
)
71+
from pymbolic.version import VERSION_TEXT as __version__ # noqa
6672

6773

6874
__all__ = (
69-
"ArithmeticExpressionT",
70-
"BoolT",
75+
"ArithmeticExpression",
76+
"Bool",
7177
"Expression",
72-
"ExpressionT",
73-
"NumberT",
74-
"ScalarT",
78+
"ExpressionNode",
79+
"Number",
80+
"Scalar",
7581
"Variable",
7682
"compile",
7783
"compiler",
@@ -105,3 +111,10 @@
105111
"var",
106112
"variables",
107113
)
114+
115+
__getattr__ = partial(module_getattr_for_deprecations, __name__, {
116+
"ExpressionT": ("pymbolic.typing.Expression", _TypingExpression, 2026),
117+
"ArithmeticExpressionT": ("ArithmeticExpression", ArithmeticExpression, 2026),
118+
"BoolT": ("Bool", Bool, 2026),
119+
"ScalarT": ("Scalar", Scalar, 2026),
120+
})

pymbolic/cse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def tag_common_subexpressions(exprs):
137137
get_key = NormalizedKeyGetter()
138138
ucm = UseCountMapper(get_key)
139139

140-
if isinstance(exprs, prim.Expression):
140+
if isinstance(exprs, prim.ExpressionNode):
141141
raise TypeError("exprs should be an iterable of expressions")
142142

143143
for expr in exprs:

pymbolic/geometric_algebra/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from pytools import memoize, memoize_method
3434

3535
from pymbolic.primitives import expr_dataclass, is_zero
36-
from pymbolic.typing import ArithmeticExpressionT, T
36+
from pymbolic.typing import ArithmeticExpression, T
3737

3838

3939
__doc__ = """
@@ -293,7 +293,7 @@ def get_euclidean_space(n: int) -> Space:
293293
# }}}
294294

295295

296-
CoeffT = TypeVar("CoeffT", bound=ArithmeticExpressionT)
296+
CoeffT = TypeVar("CoeffT", bound=ArithmeticExpression)
297297

298298

299299
# {{{ blade product weights
@@ -428,7 +428,7 @@ def _cast_to_mv(obj: Any, space: Space) -> MultiVector:
428428
class MultiVector(Generic[CoeffT]):
429429
r"""An immutable multivector type. Its implementation follows [DFM].
430430
It is pickleable, and not picky about what data is used as coefficients.
431-
It supports :class:`pymbolic.primitives.Expression` objects of course,
431+
It supports :class:`pymbolic.primitives.ExpressionNode` objects of course,
432432
but it can take just about any other scalar-ish coefficients.
433433
434434
.. autoattribute:: data

pymbolic/geometric_algebra/mapper.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,23 @@
4949
PREC_NONE,
5050
StringifyMapper as StringifyMapperBase,
5151
)
52-
from pymbolic.primitives import Expression
52+
from pymbolic.primitives import ExpressionNode
5353

5454

5555
class IdentityMapper(IdentityMapperBase[P]):
5656
def map_nabla(
57-
self, expr: prim.Nabla, *args: P.args, **kwargs: P.kwargs) -> Expression:
57+
self, expr: prim.Nabla, *args: P.args, **kwargs: P.kwargs
58+
) -> ExpressionNode:
5859
return expr
5960

6061
def map_nabla_component(self,
61-
expr: prim.NablaComponent, *args: P.args, **kwargs: P.kwargs) -> Expression:
62+
expr: prim.NablaComponent, *args: P.args, **kwargs: P.kwargs
63+
) -> ExpressionNode:
6264
return expr
6365

6466
def map_derivative_source(self,
6567
expr: prim.DerivativeSource, *args: P.args, **kwargs: P.kwargs
66-
) -> Expression:
68+
) -> ExpressionNode:
6769
operand = self.rec(expr.operand, *args, **kwargs)
6870
if operand is expr.operand:
6971
return expr

pymbolic/geometric_algebra/primitives.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
from collections.abc import Hashable
3030
from typing import ClassVar
3131

32-
from pymbolic.primitives import Expression, Variable, expr_dataclass
33-
from pymbolic.typing import ExpressionT
32+
from pymbolic.primitives import ExpressionNode, Variable, expr_dataclass
33+
from pymbolic.typing import Expression
3434

3535

3636
class MultiVectorVariable(Variable):
@@ -39,7 +39,7 @@ class MultiVectorVariable(Variable):
3939

4040
# {{{ geometric calculus
4141

42-
class _GeometricCalculusExpression(Expression):
42+
class _GeometricCalculusExpression(ExpressionNode):
4343
def stringifier(self):
4444
from pymbolic.geometric_algebra.mapper import StringifyMapper
4545
return StringifyMapper
@@ -58,7 +58,7 @@ class Nabla(_GeometricCalculusExpression):
5858

5959
@expr_dataclass()
6060
class DerivativeSource(_GeometricCalculusExpression):
61-
operand: ExpressionT
61+
operand: Expression
6262
nabla_id: Hashable
6363

6464

pymbolic/interop/ast.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import pymbolic.primitives as p
3333
from pymbolic.mapper import CachedMapper
34-
from pymbolic.typing import ExpressionT
34+
from pymbolic.typing import Expression
3535

3636

3737
__doc__ = r'''
@@ -263,7 +263,7 @@ def map_variable(self, expr) -> ast.expr:
263263
return ast.Name(id=expr.name)
264264

265265
def _map_multi_children_op(self,
266-
children: tuple[ExpressionT, ...],
266+
children: tuple[Expression, ...],
267267
op_type: ast.operator) -> ast.expr:
268268
rec_children = [self.rec(child) for child in children]
269269
result = rec_children[-1]
@@ -435,7 +435,7 @@ def to_python_ast(expr) -> ast.expr:
435435
return PymbolicToASTMapper()(expr)
436436

437437

438-
def to_evaluatable_python_function(expr: ExpressionT,
438+
def to_evaluatable_python_function(expr: Expression,
439439
fn_name: str
440440
) -> str:
441441
"""

pymbolic/interop/matchpy/__init__.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@
5757
)
5858

5959
import pymbolic.primitives as p
60-
from pymbolic.typing import ScalarT
60+
from pymbolic.typing import Scalar as PbScalar
6161

6262

6363
ExprT: TypeAlias = Expression
6464
ConstantT = TypeVar("ConstantT")
65-
ToMatchpyT = Callable[[p.Expression], ExprT]
66-
FromMatchpyT = Callable[[ExprT], p.Expression]
65+
ToMatchpyT = Callable[[p.ExpressionNode], ExprT]
66+
FromMatchpyT = Callable[[ExprT], p.ExpressionNode]
6767

6868

6969
_NOT_OPERAND_METADATA = {"not_an_operand": True}
@@ -95,7 +95,7 @@ def __lt__(self, other):
9595

9696

9797
@op_dataclass
98-
class Scalar(_Constant[ScalarT]):
98+
class Scalar(_Constant[PbScalar]):
9999
_mapper_method: str = "map_scalar"
100100

101101

@@ -360,11 +360,11 @@ def _get_operand_at_path(expr: PymbolicOp, path: tuple[int, ...]) -> PymbolicOp:
360360
return result
361361

362362

363-
def match(subject: p.Expression,
364-
pattern: p.Expression,
363+
def match(subject: p.ExpressionNode,
364+
pattern: p.ExpressionNode,
365365
to_matchpy_expr: ToMatchpyT | None = None,
366366
from_matchpy_expr: FromMatchpyT | None = None
367-
) -> Iterator[Mapping[str, p.Expression | ScalarT]]:
367+
) -> Iterator[Mapping[str, p.ExpressionNode | PbScalar]]:
368368
from matchpy import Pattern, match
369369

370370
from .tofrom import FromMatchpyExpressionMapper, ToMatchpyExpressionMapper
@@ -383,12 +383,12 @@ def match(subject: p.Expression,
383383
for name, expr in subst.items()}
384384

385385

386-
def match_anywhere(subject: p.Expression,
387-
pattern: p.Expression,
386+
def match_anywhere(subject: p.ExpressionNode,
387+
pattern: p.ExpressionNode,
388388
to_matchpy_expr: ToMatchpyT | None = None,
389389
from_matchpy_expr: FromMatchpyT | None = None
390-
) -> Iterator[tuple[Mapping[str, p.Expression | ScalarT],
391-
p.Expression | ScalarT]
390+
) -> Iterator[tuple[Mapping[str, p.ExpressionNode | PbScalar],
391+
p.ExpressionNode | PbScalar]
392392
]:
393393
from matchpy import Pattern, match_anywhere
394394

@@ -409,8 +409,8 @@ def match_anywhere(subject: p.Expression,
409409
from_matchpy_expr(_get_operand_at_path(m_subject, path)))
410410

411411

412-
def make_replacement_rule(pattern: p.Expression,
413-
replacement: Callable[..., p.Expression],
412+
def make_replacement_rule(pattern: p.ExpressionNode,
413+
replacement: Callable[..., p.ExpressionNode],
414414
to_matchpy_expr: ToMatchpyT | None = None,
415415
from_matchpy_expr: FromMatchpyT | None = None
416416
) -> ReplacementRule:
@@ -437,11 +437,11 @@ def make_replacement_rule(pattern: p.Expression,
437437
from_matchpy_expr))
438438

439439

440-
def replace_all(expression: p.Expression,
440+
def replace_all(expression: p.ExpressionNode,
441441
rules: Iterable[ReplacementRule],
442442
to_matchpy_expr: ToMatchpyT | None = None,
443443
from_matchpy_expr: FromMatchpyT | None = None
444-
) -> p.Expression | tuple[p.Expression, ...]:
444+
) -> p.ExpressionNode | tuple[p.ExpressionNode, ...]:
445445
import collections.abc as abc
446446

447447
from matchpy import replace_all

pymbolic/interop/matchpy/tofrom.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import pymbolic.primitives as p
1313
from pymbolic.interop.matchpy.mapper import Mapper as BaseMatchPyMapper
1414
from pymbolic.mapper import Mapper as BasePymMapper
15+
from pymbolic.typing import Scalar as PbScalar
1516

1617

1718
# {{{ to matchpy
@@ -117,7 +118,7 @@ def map_star_wildcard(self, expr: p.StarWildcard) -> m.Wildcard:
117118
# {{{ from matchpy
118119

119120
class FromMatchpyExpressionMapper(BaseMatchPyMapper):
120-
def map_scalar(self, expr: m.Scalar) -> m.ScalarT:
121+
def map_scalar(self, expr: m.Scalar) -> PbScalar:
121122
return expr.value
122123

123124
def map_variable(self, expr: m.Variable) -> p.Variable:
@@ -200,7 +201,7 @@ def map_if(self, expr: m.If) -> p.If:
200201

201202
@dataclass(frozen=True, eq=True)
202203
class ToFromReplacement:
203-
f: Callable[..., p.Expression]
204+
f: Callable[..., p.ExpressionNode]
204205
to_matchpy_expr: m.ToMatchpyT
205206
from_matchpy_expr: m.FromMatchpyT
206207

0 commit comments

Comments
 (0)