Skip to content

Commit

Permalink
bug fix - remove sympy __getitem__
Browse files Browse the repository at this point in the history
was causing iter() calls to not fail, then makes it looks like the item is iterable
e.g. np.iterable would return true
specifically matplotlib ax.set_xlim(0,1.2) would fail, as it would get a rational.
  • Loading branch information
idanpa committed Mar 4, 2024
1 parent 440e7f9 commit f09f6ec
Showing 1 changed file with 0 additions and 9 deletions.
9 changes: 0 additions & 9 deletions calcpy/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,7 @@ def init(ip: IPython.InteractiveShell):

ip.set_custom_exc((SyntaxError,), syntax_error_handler)

def sympy_expr_getitem(self, args):
if not isinstance(args, tuple):
args = (args,)
sorted_symbols = sorted(self.free_symbols, key=lambda s: s.name)
if len(args) != len(sorted_symbols):
raise TypeError(f'Expected {len(sorted_symbols)} arguments {sorted_symbols}')
return self.subs(zip(sorted_symbols, args))

# monkey patches
sympy.Expr.__getitem__ = sympy_expr_getitem
# don't consider expressions as iterables: (see iterable() in sympy\utilities\iterables.py)
sympy.Expr._iterable = False
sympy.Expr.real = property(sympy.re)
Expand Down

0 comments on commit f09f6ec

Please sign in to comment.