|
5 | 5 | from distutils.version import LooseVersion
|
6 | 6 | from functools import partial
|
7 | 7 | import operator as op
|
| 8 | +from typing import Callable, Iterable, Union |
8 | 9 |
|
9 | 10 | import numpy as np
|
10 | 11 |
|
@@ -196,10 +197,10 @@ class Op:
|
196 | 197 | Hold an operator of arbitrary arity.
|
197 | 198 | """
|
198 | 199 |
|
199 |
| - def __init__(self, op, operands, *args, **kwargs): |
| 200 | + def __init__(self, op: str, operands: Iterable[Union[Term, "Op"]], encoding=None): |
200 | 201 | self.op = _bool_op_map.get(op, op)
|
201 | 202 | self.operands = operands
|
202 |
| - self.encoding = kwargs.get("encoding", None) |
| 203 | + self.encoding = encoding |
203 | 204 |
|
204 | 205 | def __iter__(self):
|
205 | 206 | return iter(self.operands)
|
@@ -333,11 +334,11 @@ class BinOp(Op):
|
333 | 334 | Parameters
|
334 | 335 | ----------
|
335 | 336 | op : str
|
336 |
| - left : Term or Op |
337 |
| - right : Term or Op |
| 337 | + lhs : Term or Op |
| 338 | + rhs : Term or Op |
338 | 339 | """
|
339 | 340 |
|
340 |
| - def __init__(self, op, lhs, rhs, **kwargs): |
| 341 | + def __init__(self, op: str, lhs: Union[Term, Op], rhs: Union[Term, Op]): |
341 | 342 | super().__init__(op, (lhs, rhs))
|
342 | 343 | self.lhs = lhs
|
343 | 344 | self.rhs = rhs
|
@@ -369,10 +370,6 @@ def __call__(self, env):
|
369 | 370 | object
|
370 | 371 | The result of an evaluated expression.
|
371 | 372 | """
|
372 |
| - # handle truediv |
373 |
| - if self.op == "/" and env.scope["truediv"]: |
374 |
| - self.func = op.truediv |
375 |
| - |
376 | 373 | # recurse over the left/right nodes
|
377 | 374 | left = self.lhs(env)
|
378 | 375 | right = self.rhs(env)
|
@@ -431,6 +428,7 @@ def convert_values(self):
|
431 | 428 | """
|
432 | 429 |
|
433 | 430 | def stringify(value):
|
| 431 | + encoder: Callable |
434 | 432 | if self.encoding is not None:
|
435 | 433 | encoder = partial(pprint_thing_encoded, encoding=self.encoding)
|
436 | 434 | else:
|
@@ -483,13 +481,10 @@ class Div(BinOp):
|
483 | 481 | ----------
|
484 | 482 | lhs, rhs : Term or Op
|
485 | 483 | The Terms or Ops in the ``/`` expression.
|
486 |
| - truediv : bool |
487 |
| - Whether or not to use true division. With Python 3 this happens |
488 |
| - regardless of the value of ``truediv``. |
489 | 484 | """
|
490 | 485 |
|
491 |
| - def __init__(self, lhs, rhs, truediv, *args, **kwargs): |
492 |
| - super().__init__("/", lhs, rhs, *args, **kwargs) |
| 486 | + def __init__(self, lhs: Union[Term, Op], rhs: Union[Term, Op]): |
| 487 | + super().__init__("/", lhs, rhs) |
493 | 488 |
|
494 | 489 | if not isnumeric(lhs.return_type) or not isnumeric(rhs.return_type):
|
495 | 490 | raise TypeError(
|
|
0 commit comments