26
26
27
27
28
28
if _TYPE_CHECKING :
29
- from typing import Optional , Iterable , Any
29
+ from typing import Optional , Sequence , Any
30
30
31
31
Op1 = Callable [[_T ], _T ]
32
32
Op2 = Callable [[_T , _T ], _T ]
33
- OpN = Callable [[Iterable [_T ]], _T ]
33
+ OpN = Callable [[Sequence [_T ]], _T ]
34
34
35
35
36
- def _generic_operation_error (head : TreeExpr , argvals : Iterable [_T ]) -> _T :
36
+ def _generic_operation_error (head : TreeExpr , argvals : Sequence [_T ]) -> _T :
37
37
"""Error fallback rule for handling unknown heads."""
38
38
msg = "No rule for head: " + repr (head )
39
39
raise NoEvaluationRuleError (msg )
@@ -91,7 +91,7 @@ class Evaluator(Generic[_T]):
91
91
92
92
atoms : dict [AtomType [_AnyValue ], Callable [[_AnyValue ], _T ]]
93
93
operations : dict [TreeExpr , tuple [Callable [..., _T ], bool ]]
94
- generic_operation_func : Callable [[TreeExpr , Iterable [_T ]], _T ]
94
+ generic_operation_func : Callable [[TreeExpr , Sequence [_T ]], _T ]
95
95
generic_atom_func : Callable [[TreeAtom [_S ]], _T ]
96
96
97
97
def __init__ (self ) -> None :
@@ -123,7 +123,7 @@ def add_opn(self, head: TreeExpr, func: OpN[_T]) -> None:
123
123
"""Add an evaluation rule for a particular head."""
124
124
self .operations [head ] = (func , False )
125
125
126
- def add_op_generic (self , func : Callable [[TreeExpr , Iterable [_T ]], _T ]) -> None :
126
+ def add_op_generic (self , func : Callable [[TreeExpr , Sequence [_T ]], _T ]) -> None :
127
127
"""Add a generic fallback rule for heads."""
128
128
self .generic_operation_func = func
129
129
@@ -135,7 +135,7 @@ def eval_atom(self, atom: TreeAtom[_S]) -> _T:
135
135
return self .generic_atom_func (atom )
136
136
return atom_func (atom_value .value )
137
137
138
- def eval_operation (self , head : TreeExpr , argvals : Iterable [_T ]) -> _T :
138
+ def eval_operation (self , head : TreeExpr , argvals : Sequence [_T ]) -> _T :
139
139
"""Evaluate one function with some values."""
140
140
func_star = self .operations .get (head )
141
141
0 commit comments