1
+ from __future__ import annotations
2
+
3
+
1
4
__copyright__ = """
2
5
Copyright (C) 2015 Andreas Kloeckner
3
6
Copyright (C) 2022 Kaushik Kulkarni
24
27
"""
25
28
26
29
import ast
27
- from typing import Any , ClassVar , Dict , List , Tuple , Type
30
+ from typing import Any , ClassVar
28
31
29
32
import pymbolic .primitives as p
30
- from pymbolic .typing import ExpressionT , ScalarT
31
33
from pymbolic .mapper import CachedMapper
34
+ from pymbolic .typing import ExpressionT , ScalarT
35
+
32
36
33
37
__doc__ = r'''
34
38
@@ -113,7 +117,7 @@ def _neg(x):
113
117
114
118
class ASTToPymbolic (ASTMapper ):
115
119
116
- bin_op_map : ClassVar [Dict [ Type [ast .operator ], Any ]] = {
120
+ bin_op_map : ClassVar [dict [ type [ast .operator ], Any ]] = {
117
121
ast .Add : _add ,
118
122
ast .Sub : _sub ,
119
123
ast .Mult : _mult ,
@@ -139,7 +143,7 @@ def map_BinOp(self, expr): # noqa
139
143
140
144
return op_constructor (self .rec (expr .left ), self .rec (expr .right ))
141
145
142
- unary_op_map : ClassVar [Dict [ Type [ast .unaryop ], Any ]] = {
146
+ unary_op_map : ClassVar [dict [ type [ast .unaryop ], Any ]] = {
143
147
ast .Invert : _neg ,
144
148
ast .Not : p .LogicalNot ,
145
149
# ast.UAdd:
@@ -160,7 +164,7 @@ def map_IfExp(self, expr): # noqa
160
164
# (expr test, expr body, expr orelse)
161
165
return p .If (self .rec (expr .test ), self .rec (expr .body ), self .rec (expr .orelse ))
162
166
163
- comparison_op_map : ClassVar [Dict [ Type [ast .cmpop ], str ]] = {
167
+ comparison_op_map : ClassVar [dict [ type [ast .cmpop ], str ]] = {
164
168
ast .Eq : "==" ,
165
169
ast .NotEq : "!=" ,
166
170
ast .Lt : "<" ,
@@ -264,7 +268,7 @@ def map_variable(self, expr) -> ast.expr:
264
268
return ast .Name (id = expr .name )
265
269
266
270
def _map_multi_children_op (self ,
267
- children : Tuple [ExpressionT , ...],
271
+ children : tuple [ExpressionT , ...],
268
272
op_type : ast .operator ) -> ast .expr :
269
273
rec_children = [self .rec (child ) for child in children ]
270
274
result = rec_children [- 1 ]
@@ -366,10 +370,10 @@ def map_logical_and(self, expr) -> ast.expr:
366
370
return ast .BoolOp (ast .And (), [self .rec (child )
367
371
for child in expr .children ])
368
372
369
- def map_list (self , expr : List [Any ]) -> ast .expr :
373
+ def map_list (self , expr : list [Any ]) -> ast .expr :
370
374
return ast .List ([self .rec (el ) for el in expr ])
371
375
372
- def map_tuple (self , expr : Tuple [Any , ...]) -> ast .expr :
376
+ def map_tuple (self , expr : tuple [Any , ...]) -> ast .expr :
373
377
return ast .Tuple ([self .rec (el ) for el in expr ])
374
378
375
379
def map_if (self , expr : p .If ) -> ast .expr :
@@ -465,6 +469,7 @@ def foo(*, E, S):
465
469
return S // 32 + E % 32
466
470
"""
467
471
import sys
472
+
468
473
from pymbolic .mapper .dependency import CachedDependencyMapper
469
474
470
475
if sys .version_info < (3 , 9 ):
0 commit comments