[New-bugs-announce] [issue5567] Operators in operator module don't work with keyword arguments

Marek Kubica report at bugs.python.org
Thu Mar 26 16:48:18 CET 2009


New submission from Marek Kubica <marek at xivilization.net>:

When calling operators from the ``operator``-module, they refuse to
accept keyword arguments:

operator.add(a=1, b=2)
TypeError: add() takes no keyword arguments

Operators with keyword arguments are important when one wants to create
partial functions with non-positional arguments.

Take for example ``operator.mod`` where the order of the arguments matters:

This works:
map(lambda x: x % 2, range(5))

This does not work, since ``operator.mod`` does not support keyword
arguments:
map(functools.partial(operator.mod, b=2), range(5))

So there are two solutions: define one's own add(), mod(), contains()
etc. but then the ``operator`` module is rather useless or make them
accept keyword arguments. With ``partial`` in the Stdlib this solution
would be a whole lot nicer.

----------
components: Library (Lib)
messages: 84181
nosy: leonidas
severity: normal
status: open
title: Operators in operator module don't work with keyword arguments
type: feature request

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


More information about the New-bugs-announce mailing list