Patches item #1460496, was opened at 2006-03-29 07:30 Message generated for change (Comment added) made by gbrandl You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1460496&group_id=5470
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: Closed >Resolution: Accepted Priority: 5 Submitted By: Wesley J. Chun (wesc) Assigned to: Nobody/Anonymous (nobody) Summary: give round() kwargs (mostly for PFAs) Initial Comment: 1. WHAT 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. 3. MOTIVATION similar to the example in the Python Lib Ref doc page for the functional module and its use with int()... http://docs.python.org/dev/lib/module-functional.html >>> basetwo = partial(int, base=2) >>> basetwo.__doc__ = 'Convert base 2 string to an int.' >>> basetwo('10010') 18 ...we should also allow round() to be used in the same way... >>> from functional import partial >>> >>> roundTwo = partial(round, ndigits=2) >>> print '%.2f' % roundTwo(1.5555555) 1.56 >>> print '%.2f' % roundTwo(1.5545555) 1.55 >>> print '%.2f' % roundTwo(1.5445555) 1.54 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 4. THE FIX 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. 5. TESTING as mentioned above, we ran the test/test_builtin.py script and there are no changes in the execution of test_round: : 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: Georg Brandl (gbrandl) Date: 2006-03-31 18:55 Message: Logged In: YES user_id=849994 Added tests and checked in in rev. 43496. ---------------------------------------------------------------------- Comment By: Tim Peters (tim_one) Date: 2006-03-31 18:32 Message: Logged In: YES user_id=31435 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: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1460496&group_id=5470 _______________________________________________ Patches mailing list [email protected] http://mail.python.org/mailman/listinfo/patches
