[issue12909] Inconsistent exception usage in PyLong_As* C functions
Mark Dickinson dicki...@gmail.com added the comment: Looks good to me. I'd prefer 'test_long_as_size' to be called 'test_long_as_size_t' (even though that's inaccurate for the ssize_t bits :-). The 'Py_None' reference counting in test_long_as_size and test_long_as_double looked a little odd at first glance---particularly the lack of a Py_INCREF just before the return Py_None. I see that it works; it just caught my eye. Anyway, those are just nitpicks; I leave it to you whether you want to change anything. Otherwise, please go ahead and apply. Thanks for the patches! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 4a66a35da3fd by Nadeem Vawda in branch 'default': Issue #12909: Make PyLong_As* functions consistent in their use of exceptions. http://hg.python.org/cpython/rev/4a66a35da3fd -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
Nadeem Vawda nadeem.va...@gmail.com added the comment: The 'Py_None' reference counting in test_long_as_size and test_long_as_double looked a little odd at first glance Indeed, it is rather roundabout, so I added a comment to avoid confusion. Anyway, those are just nitpicks; I leave it to you whether you want to change anything. Otherwise, please go ahead and apply. Thanks for the patches! Thanks for the review. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
Changes by Nadeem Vawda nadeem.va...@gmail.com: -- resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
Raymond Hettinger raymond.hettin...@gmail.com added the comment: +1 -- assignee: nadeem.vawda - rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
New submission from Nadeem Vawda nadeem.va...@gmail.com: The C functions for converting a Python 'int' object to a C integer are inconsistent about what exception gets raised when the object passed to them is not an integer. Most of these functions raise a TypeError, but PyLong_AsUnsignedLongLong() and PyLong_AsDouble() raise a SystemError instead. Raising a SystemError here is quite unhelpful. My understanding is that it is intended to indicate internal programming errors, so an extension module should not raise one when (for example) a function is passed an argument of the incorrect type. In such a case, raising a TypeError is a reasonable default. Is there any reason not to change the behaviour of these two functions to be consistent with their siblings? -- components: Interpreter Core messages: 143588 nosy: nadeem.vawda, pitrou priority: normal severity: normal stage: needs patch status: open title: Inconsistent exception usage in PyLong_As* C functions type: behavior versions: Python 3.2, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +mark.dickinson, rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
Mark Dickinson dicki...@gmail.com added the comment: +1 for turning these into TypeErrors. It makes little sense that PyLong_AsLongLong and PyLong_AsUnsignedLongLong behave differently here. Do you have a patch handy? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
Nadeem Vawda nadeem.va...@gmail.com added the comment: Do you have a patch handy? See attached. -- keywords: +patch Added file: http://bugs.python.org/file23106/pylong-exceptions.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
Nadeem Vawda nadeem.va...@gmail.com added the comment: This probably shouldn't be backported to 3.2; it could break 3rd-party extension modules (though I would hope that nothing depends on this behaviour...). Also, it's worth noting that the error handling between conversion functions still isn't completely consistent - some attempt to coerce the argument to an integer using type-tp_as_number-nb_int, while others fail immediately when they see that PyLong_Check() fails. That's a less pressing issue, though. -- stage: needs patch - patch review versions: -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
Mark Dickinson dicki...@gmail.com added the comment: This probably shouldn't be backported to 3.2 Agreed; I don't see this as a bugfix (especially since AFAIK it's not documented that TypeError should be raised here); rather, as a design improvement. Also, it's worth noting that the error handling between conversion functions still isn't completely consistent True; there are a number of inconsistencies left. We'll get them all eventually. :-) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
Mark Dickinson dicki...@gmail.com added the comment: The patch still needs tests (e.g., in test_capi). I'm not sure whether it would be good to add information about the TypeError to the docs. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12909] Inconsistent exception usage in PyLong_As* C functions
Nadeem Vawda nadeem.va...@gmail.com added the comment: Attached is an updated patch with tests. There don't seem to be any tests for PyLong_AsS[s]ize_t() and PyLong_AsDouble(), so I added new ones for this issue. They should still be expanded on at some point in the future, but for the meanwhile this should be sufficient. I'm not sure whether it would be good to add information about the TypeError to the docs. Yeah, that doesn't seem necessary; raising TypeError in this sort of situation is sufficiently typical behavior that explicitly documenting it feels redundant. -- assignee: - nadeem.vawda Added file: http://bugs.python.org/file23110/pylong-exceptions.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com