Skip to content

Commit ae4b10e

Browse files
committed
stream ops: fix bug in optional argument handling, clarify variables
1 parent 6ac0ba1 commit ae4b10e

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

unpythonic/mathseq.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -585,26 +585,26 @@ def mathify(*args, **kwargs):
585585
# The *settings mechanism is used by round and pow.
586586
# These are recursive to support iterables containing iterables (e.g. an iterable of math sequences).
587587
def _make_termwise_stream_unop(op, *settings):
588-
def sop(a):
588+
def stream_op(a):
589589
if hasattr(a, "__iter__"):
590-
return m(sop(x, *settings) for x in a)
590+
return m(stream_op(x) for x in a)
591591
return op(a, *settings)
592-
return sop
592+
return stream_op
593593
def _make_termwise_stream_binop(op, *settings):
594-
def sop(a, b):
595-
ig = [hasattr(x, "__iter__") for x in (a, b)]
596-
if all(ig):
594+
def stream_op(a, b):
595+
isiterable = [hasattr(x, "__iter__") for x in (a, b)]
596+
if all(isiterable):
597597
# it's very convenient here that zip() terminates when the shorter input runs out.
598-
return m(sop(x, y, *settings) for x, y in zip(a, b))
599-
elif ig[0]:
598+
return m(stream_op(x, y) for x, y in zip(a, b))
599+
elif isiterable[0]:
600600
c = b
601-
return m(sop(x, c, *settings) for x in a)
602-
elif ig[1]:
601+
return m(stream_op(x, c) for x in a)
602+
elif isiterable[1]:
603603
c = a
604-
return m(sop(c, y, *settings) for y in b) # careful; op might not be commutative
605-
else: # not any(ig):
604+
return m(stream_op(c, y) for y in b) # careful; op might not be commutative
605+
else: # not any(isiterable):
606606
return op(a, b, *settings)
607-
return sop
607+
return stream_op
608608

609609
# We expose the full set of "m" operators also as functions à la the ``operator`` module.
610610
_add = _make_termwise_stream_binop(primitive_add)

0 commit comments

Comments
 (0)