bpo-32582: chr() doesn't raise OverflowError anymore#5218
bpo-32582: chr() doesn't raise OverflowError anymore#5218vstinner wants to merge 3 commits intopython:masterfrom vstinner:chr_overflow
Conversation
chr() now catchs OverflowError and raises a ValueError exception instead.
Python/bltinmodule.c
Outdated
| return NULL; | ||
| } | ||
| PyErr_Clear(); | ||
| ch = -1; |
There was a problem hiding this comment.
We don't need this line, right?
There was a problem hiding this comment.
Oops, right. I removed this useless assignment.
My intent was to get a different error message for underflow (< 0) or overflow (> 0). But in fact, the same error message for all cases is just fine.
|
Hum, this PR changes the exception type for large float. Patched: Python 3.6: |
|
Ahh, yes. And now it could accept small float while not the case before. So still need to call "PyArg_Parse" and catch OverflowError then. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Needed updating the chr() documentation an an entry in the What's New document, in the section "Porting to 3.7".
| self.assertRaises(ValueError, chr, -1) | ||
| self.assertRaises(ValueError, chr, 0x00110000) | ||
| self.assertRaises((OverflowError, ValueError), chr, 2**32) | ||
| self.assertRaises(ValueError, chr, -2**100) |
There was a problem hiding this comment.
Use 2**1000. It is possible that once Python will run platform with 128-bit C long.
| /*[clinic end generated code: output=d34f25b8035a9b10 input=f919867f0ba2f496]*/ | ||
| { | ||
| return PyUnicode_FromOrdinal(i); | ||
| int ch = _PyLong_AsInt(i); |
There was a problem hiding this comment.
It is better to use PyLongAsLongAndOverflow().
| @@ -0,0 +1,2 @@ | |||
| The :func:`chr` builtin function now catchs :exc:`OverflowError` and raises | |||
There was a problem hiding this comment.
"catches" -- this is an implementation detail. And I think it is better to not raise and catch it.
chr() now catchs OverflowError and raises a ValueError exception
instead.
https://bugs.python.org/issue32582