Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug #125 (dataclasses for expressions) #147

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
downstream_tests:
strategy:
matrix:
downstream_project: [loopy, pytential, pytato]
downstream_project: [pytential]
fail-fast: false
name: Tests for downstream project ${{ matrix.downstream_project }}
runs-on: ubuntu-latest
Expand All @@ -99,6 +99,7 @@ jobs:
env:
DOWNSTREAM_PROJECT: ${{ matrix.downstream_project }}
run: |
sleep 2h
curl -L -O https://tiker.net/ci-support-v0
. ./ci-support-v0
test_downstream "$DOWNSTREAM_PROJECT"
Expand Down
14 changes: 7 additions & 7 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ You can also easily define your own objects to use inside an expression:

.. doctest::

>>> from pymbolic.primitives import Expression
>>> class FancyOperator(Expression):
... def __init__(self, operand):
... self.operand = operand
...
... def __getinitargs__(self):
... return (self.operand,)
>>> from pymbolic.primitives import Expression, augment_expression_dataclass
>>> from dataclasses import dataclass
>>>
>>> @augment_expression_dataclass
... @dataclass(frozen=True)
... class FancyOperator(Expression):
... operand: Expression
...
... mapper_method = "map_fancy_operator"
...
Expand Down
7 changes: 7 additions & 0 deletions pymbolic/mapper/persistent_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""


from warnings import warn
from pymbolic.mapper import WalkMapper


Expand All @@ -33,6 +34,12 @@ class PersistentHashWalkMapper(WalkMapper):
def __init__(self, key_hash):
self.key_hash = key_hash

warn("PersistentHashWalkMapper is deprecated. "
"Since they are dataclasses, expression objects should now "
"support persistent hashing natively without any help. "
"It will be removed in 2026.",
DeprecationWarning, stacklevel=2)

def visit(self, expr):
self.key_hash.update(type(expr).__name__.encode("utf8"))
return True
Expand Down
5 changes: 4 additions & 1 deletion pymbolic/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from sys import intern
from typing import ClassVar, Dict, List, Tuple

from immutabledict import immutabledict

import pytools.lex
from pytools import memoize_method

Expand Down Expand Up @@ -333,7 +335,8 @@ def parse_postfix(self, pstate, min_precedence, left_exp):
args, kwargs = self.parse_arglist(pstate)

if kwargs:
left_exp = primitives.CallWithKwargs(left_exp, args, kwargs)
left_exp = primitives.CallWithKwargs(
left_exp, args, immutabledict(kwargs))
else:
left_exp = primitives.Call(left_exp, args)

Expand Down
Loading
Loading