[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-07 Thread Roundup Robot
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset e4617650f006 by Larry Hastings in branch 'default': Issue #14705: Added support for the new 'p' format unit to skipitem(). http://hg.python.org/cpython/rev/e4617650f006 --

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-06 Thread Larry Hastings
Changes by Larry Hastings la...@hastings.org: -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14705 ___ ___

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Larry Hastings
Larry Hastings la...@hastings.org added the comment: Attached is rev 3 of my patch, incorporating mainly backing out of dumb ideas. Thanks for the feedback, Serhiy and Mark! My name is Serhiy. :) My genuine apologies! In my defense it was rather late. 'P' has the advantage that you can

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Benjamin Peterson
Benjamin Peterson benja...@python.org added the comment: Since no one has produced a good example needing P, I say drop it. At any rate, it can be almost trivially imitated with O!. -- nosy: +benjamin.peterson ___ Python tracker

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Georg Brandl
Georg Brandl ge...@python.org added the comment: Indeed, because the code is written is not a good argument if even you yourself are -0. -- nosy: +georg.brandl ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14705

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Having meditated on it, I think either I should either just call PyErr_Occured, check for explicit failure (val 0), or explicit success (val = 0). I've opted for the last of those. Yes, I think that works; it avoids a relatively

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: I considered briefly trying to make 'P' handle subclasses of bool. Not an issue: bool can't be subclassed. :-) Python 3.2.3 (default, Apr 13 2012, 00:15:25) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type help, copyright,

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: That's not a reason to use 'P'. Why you should use 'P' in the first place? I just guided by the principle Explicit is better than implicit. Statements 'if' and 'while' I consider explicit and expect cast to bool. Implicit cast to bool in

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Larry Hastings
Larry Hastings la...@hastings.org added the comment: Serhiy, I'm having a little trouble with your English. (But I'm sure your English is far better than my... uh, anything besides English.) So let me ask a question with a clear yes/no answer: Do you still think 'P' is better than 'p'?

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: Do you still think 'P' is better than 'p'? No. I hope I haven't made a lot of mistakes in the previous sentence. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14705

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Larry Hastings
Larry Hastings la...@hastings.org added the comment: I hope I haven't made a lot of mistakes in the previous sentence. It depends, do you consider three a lot? ;-) Attached is a new patch removing 'P'. (The regrtest is still running but I don't expect any failures.) I'm guessing I won't

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Latest patch looks good to me. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14705 ___ ___

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Roundup Robot
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset bc6d28e726d8 by Larry Hastings in branch 'default': Issue #14705: Add 'p' format character to PyArg_ParseTuple* for bool support. http://hg.python.org/cpython/rev/bc6d28e726d8 -- nosy: +python-dev

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Larry Hastings
Larry Hastings la...@hastings.org added the comment: Eh, it was ready, why wait? Thanks everybody for your feedback! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14705 ___

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Raymond Hettinger
Raymond Hettinger raymond.hettin...@gmail.com added the comment: I would have expected a bool parse code to insist on a boolean, so that: int x; PyArg_ParseTupleAndKeywords(args, kwds, p:func, x); would behave the same as: PyObject *o; int x;

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Larry Hastings
Larry Hastings la...@hastings.org added the comment: I would have expected a bool parse code to insist on a boolean, I originally had a second form ('P') that insisted on a boolean as you suggest. But nobody could come up with a use case. So I removed it in the final patch. Please see

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Roundup Robot
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 709850f1ec67 by Larry Hastings in branch 'default': Update Misc/NEWS for issues #14127 and #14705. (And, technically, #10148.) http://hg.python.org/cpython/rev/709850f1ec67 --

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Larry Hastings
Changes by Larry Hastings la...@hastings.org: -- resolution: - fixed stage: patch review - committed/rejected ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14705 ___

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-05 Thread Roundup Robot
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 05274ab06182 by Larry Hastings in branch 'default': Update Misc/NEWS for issues #14127 and #14705. (And, technically, #10148.) http://hg.python.org/cpython/rev/05274ab06182 --

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Eric V. Smith
Eric V. Smith e...@trueblade.com added the comment: The patch looks good to me. Are there any places in the current code base that would use P? p seems the more useful case. Are you planning on changing existing code to use P or p, or just use it going forward? -- nosy: +eric.smith

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: I also think that 'P' looks too strict to be really useful. I can't think of too many cases where I'd really want to insist on a boolean argument (and reject values of 0 or 1). Maybe implement just 'p' for now and consider 'P' later?

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Larry Hastings
Larry Hastings la...@hastings.org added the comment: I looked through the Python sources and couldn't find any instances of a function or method with an argument that only allowed you to pass in either True or False. Serily already said he would use 'P' over 'p', although I too am

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: I think there should be a test case also where PyObject_IsTrue gives an exception (which I think can happen if __bool__ raises an exception). -- nosy: +loewis ___ Python tracker

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Larry Hastings
Larry Hastings la...@hastings.org added the comment: I think there should be a test case also where PyObject_IsTrue gives an exception (which I think can happen if __bool__ raises an exception). I'd be happy to add such a test, but I don't know of any types like that. Can anyone suggest

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: I think there should be a test case also where PyObject_IsTrue gives an exception (which I think can happen if __bool__ raises an exception). I'd be happy to add such a test, but I don't know of any types like that. Can anyone suggest

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Larry Hastings
Larry Hastings la...@hastings.org added the comment: Added test forcing a failure for 'p' (and 'P'). This made me have to handle errors a little differently, so it was definitely good to test it. Thanks for the suggestion, Martin! Also changed wording in documentation ever-so-slightly.

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Eric V. Smith
Eric V. Smith e...@trueblade.com added the comment: Now that I think about this some more, I think I'd structure the 'p' tests as: for expr in [False, None, True, 1, 0]: # add the rest self.assertEqual(bool(expr), getargs_p(expr)) Since the salient point is that 'p' returns the same value

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: Serily: why would you unhesitatingly prefer 'P' to 'p'? My name is Serhiy. :) 'P' has the advantage that you can safely backward-compatibly remove the restriction by replacing 'P' on 'p'. :) I also found some funny in-between cases.

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: Since the salient point is that 'p' returns the same value as bool(), right? Yes, and bool_new() is a candidate number one for using new feature. -- ___ Python tracker rep...@bugs.python.org

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Eric V. Smith
Eric V. Smith e...@trueblade.com added the comment: If bool_new() is going to use 'p', then my suggestion shouldn't be the only test of 'p'. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14705

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-04 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: In this line in the patch (Python/getargs.c): +if (val == -1 || PyErr_Occurred()) { Isn't that call to PyErr_Occurred() redundant? -- ___ Python tracker rep...@bugs.python.org

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-03 Thread Larry Hastings
Larry Hastings la...@hastings.org added the comment: My first patch. Adds 'p' and 'P', along with documentation and unit tests. -- keywords: +patch stage: - patch review Added file: http://bugs.python.org/file25441/larry.parse.tuple.p.and.P.1.diff

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-03 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: Patch looks good to me. I however prefer to use 'P'. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14705 ___

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-02 Thread Larry Hastings
New submission from Larry Hastings la...@hastings.org: Currently functions that parse their arguments with the PyArg_ParseTuple family which want to take a boolean-ish parameter face two choices: * take an int, then test whether or not the int is 0, or * take an object, then call

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-02 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: Yes, I too have encountered this in the process of working on issue 14626. For this purpose it is appropriate to use a special converter (with 'O'). I suppose it must be a strict сonverter; there is no point in specifying followlinks=[1,

[issue14705] Add 'bool' format character to PyArg_ParseTuple*

2012-05-02 Thread Larry Hastings
Larry Hastings la...@hastings.org added the comment: For this purpose it is appropriate to use a special converter (with 'O'). The converter works--but, then, a similar converter would also work for double, and float, and long long and many others. If long long is special enough to merit