[issue5567] Operators in operator module don't work with keyword arguments

Marek Kubica report at bugs.python.org
Thu Mar 26 18:41:32 CET 2009


Marek Kubica <marek at xivilization.net> added the comment:

Well, some Schemes have an CURRYR variant which creates partial
functions with positional arguments from the right but the current
solution with partial accepting keywords is way more flexible since I
can pre-set any arguments I like in such a function in any order. Doing
so by using keyword arguments looks cleaner than by using the position
of the argument.

Compare ``partial(operator.mod, (2, 2))`` with ``partial(operator.mod,
divisor=2)`` and at least to me, it is clearer what is happening in the
second case. Even ``partial(operator.mod, b=2)`` looks simpler, albeit
the name ``b`` is not particularly descriptive.

The names ``a`` and ``b`` as used in many operators are indeed not very
useful but renaming them wouldn't be a problem since nobody currently
depends on ``a`` or ``b`` in their code; just in the order. That said,
``a`` and ``b`` are not so bad actually, because I couldn't think of
better names for ``a`` and ``b`` in ``operator.contains(a, b)``.

The nice thing now is, that partial can indeed replace many lambdas so
not allowing partial to use operator seems just a random restriction.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5567>
_______________________________________


More information about the Python-bugs-list mailing list