[Patches] [ python-Patches-1460496 ] give round() kwargs (mostly for PFAs)

SourceForge.net noreply at sourceforge.net
Fri Mar 31 20:32:44 CEST 2006

Patches item #1460496, was opened at 2006-03-29 02:30
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Wesley J. Chun (wesc)
Assigned to: Nobody/Anonymous (nobody)
Summary: give round() kwargs (mostly for PFAs)

Initial Comment:
this is a short non-critical patch to give round()
keyword arguments for Partial Function Application
(PEP309) purposes.

2. WHY
arguments that appear on the RHS of function
declarations are hard to call when using
functional.partial because the "variable" argument is
to the left (since PFAs pretty much favor only variable
arguments to the right). if fixed arguments are to the
right (are "curried"), then we need to support keyword
args for them as much as possible to encourage their use.

similar to the example in the Python Lib Ref doc page
for the functional module and its use with int()...


>>> basetwo = partial(int, base=2)
>>> basetwo.__doc__ = 'Convert base 2 string to an int.'
>>> basetwo('10010')

...we should also allow round() to be used in the same

>>> from functional import partial
>>> roundTwo = partial(round, ndigits=2)
>>> print '%.2f' % roundTwo(1.5555555)
>>> print '%.2f' % roundTwo(1.5545555)
>>> print '%.2f' % roundTwo(1.5445555)

without this patch, users current get this:

>>> from functional import partial
>>> roundTwo = partial(round, ndigits=2)
>>> '%.2f' % roundTwo(1.5555555)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: round() takes no keyword arguments

the number variable in bltinmodule.c is renamed from
'x' to 'number', and the keyword is named 'ndigits'
after the doc string:

>>> print round.__doc__
round(number[, ndigits]) -> floating point number

this patch consists of a single file,
Python/bltinmodule.c.  the original CVS version from
Mar 28, the patched version, output from running
test/test_builtin.py, and both the C and U diff files
are included in the attached ZIP file.

as mentioned above, we ran the test/test_builtin.py
script and there are no changes in the execution of

test_repr (test.test_builtin.BuiltinTest) ... ok
test_round (test.test_builtin.BuiltinTest) ... ok
test_setattr (test.test_builtin.BuiltinTest) ... ok

the full output file is in the ZIP file.


>Comment By: Tim Peters (tim_one)
Date: 2006-03-31 13:32

Logged In: YES 

Marked as Accepted.  Thanks!

Note that, in the future, a unified diff is sufficient.  The
other stuff doesn't really help, and "hiding" the patch in
an archive file actually makes it harder for people to review.

Ah!  That all obscured something important:  the patch
doesn't add test cases.  When you add new features, you must
also add new tests.

Set the Resolution back to None.  When new tests are added,
the patch can be applied.


You can respond by visiting: 

More information about the Patches mailing list