Skip to content

Commit 08b9e4f

Browse files
committed
Base expressions on dataclasses
1 parent 6e9c0a4 commit 08b9e4f

File tree

4 files changed

+368
-422
lines changed

4 files changed

+368
-422
lines changed

doc/index.rst

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

7070
.. doctest::
7171

72-
>>> from pymbolic.primitives import Expression
73-
>>> class FancyOperator(Expression):
74-
... def __init__(self, operand):
75-
... self.operand = operand
76-
...
77-
... def __getinitargs__(self):
78-
... return (self.operand,)
72+
>>> from pymbolic.primitives import Expression, augment_expression_dataclass
73+
>>> from dataclasses import dataclass
74+
>>>
75+
>>> @augment_expression_dataclass
76+
... @dataclass(frozen=True)
77+
... class FancyOperator(Expression):
78+
... operand: Expression
7979
...
8080
... mapper_method = "map_fancy_operator"
8181
...

pymbolic/parser.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
THE SOFTWARE.
2121
"""
2222

23+
import immutables
2324
import pytools.lex
2425
from pytools import memoize_method
2526
from sys import intern
@@ -330,7 +331,8 @@ def parse_postfix(self, pstate, min_precedence, left_exp):
330331
args, kwargs = self.parse_arglist(pstate)
331332

332333
if kwargs:
333-
left_exp = primitives.CallWithKwargs(left_exp, args, kwargs)
334+
left_exp = primitives.CallWithKwargs(
335+
left_exp, args, immutables.Map(kwargs))
334336
else:
335337
left_exp = primitives.Call(left_exp, args)
336338

0 commit comments

Comments
 (0)