5
5
from distutils .version import LooseVersion
6
6
from functools import partial
7
7
import operator
8
+ from typing import Callable , Iterable , Optional , Union
8
9
9
10
import numpy as np
10
11
@@ -55,7 +56,7 @@ class UndefinedVariableError(NameError):
55
56
NameError subclass for local variables.
56
57
"""
57
58
58
- def __init__ (self , name , is_local : bool ):
59
+ def __init__ (self , name : str , is_local : Optional [ bool ] = None ):
59
60
base_msg = f"{ repr (name )} is not defined"
60
61
if is_local :
61
62
msg = f"local variable { base_msg } "
@@ -199,10 +200,10 @@ class Op:
199
200
200
201
op : str
201
202
202
- def __init__ (self , op : str , operands , * args , ** kwargs ):
203
+ def __init__ (self , op : str , operands : Iterable [ Union [ Term , "Op" ]], encoding = None ):
203
204
self .op = _bool_op_map .get (op , op )
204
205
self .operands = operands
205
- self .encoding = kwargs . get ( " encoding" , None )
206
+ self .encoding = encoding
206
207
207
208
def __iter__ (self ):
208
209
return iter (self .operands )
@@ -353,11 +354,11 @@ class BinOp(Op):
353
354
Parameters
354
355
----------
355
356
op : str
356
- left : Term or Op
357
- right : Term or Op
357
+ lhs : Term or Op
358
+ rhs : Term or Op
358
359
"""
359
360
360
- def __init__ (self , op : str , lhs , rhs , ** kwargs ):
361
+ def __init__ (self , op : str , lhs , rhs ):
361
362
super ().__init__ (op , (lhs , rhs ))
362
363
self .lhs = lhs
363
364
self .rhs = rhs
@@ -388,7 +389,6 @@ def __call__(self, env):
388
389
object
389
390
The result of an evaluated expression.
390
391
"""
391
-
392
392
# recurse over the left/right nodes
393
393
left = self .lhs (env )
394
394
right = self .rhs (env )
@@ -416,13 +416,15 @@ def evaluate(self, env, engine: str, parser, term_type, eval_in_python):
416
416
res = self (env )
417
417
else :
418
418
# recurse over the left/right nodes
419
+
419
420
left = self .lhs .evaluate (
420
421
env ,
421
422
engine = engine ,
422
423
parser = parser ,
423
424
term_type = term_type ,
424
425
eval_in_python = eval_in_python ,
425
426
)
427
+
426
428
right = self .rhs .evaluate (
427
429
env ,
428
430
engine = engine ,
@@ -447,6 +449,7 @@ def convert_values(self):
447
449
"""
448
450
449
451
def stringify (value ):
452
+ encoder : Callable
450
453
if self .encoding is not None :
451
454
encoder = partial (pprint_thing_encoded , encoding = self .encoding )
452
455
else :
@@ -501,8 +504,8 @@ class Div(BinOp):
501
504
The Terms or Ops in the ``/`` expression.
502
505
"""
503
506
504
- def __init__ (self , lhs , rhs , ** kwargs ):
505
- super ().__init__ ("/" , lhs , rhs , ** kwargs )
507
+ def __init__ (self , lhs , rhs ):
508
+ super ().__init__ ("/" , lhs , rhs )
506
509
507
510
if not isnumeric (lhs .return_type ) or not isnumeric (rhs .return_type ):
508
511
raise TypeError (
0 commit comments