-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-32582: chr() doesn't raise OverflowError anymore #5218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Core and Builtins/2018-01-17-15-42-56.bpo-32582.kSu6Yj.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
The :func:`chr` builtin function now catchs :exc:`OverflowError` and raises | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "catches" -- this is an implementation detail. And I think it is better to not raise and catch it. |
||
a :exc:`ValueError` exception instead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -715,17 +715,24 @@ builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec) | |
/*[clinic input] | ||
chr as builtin_chr | ||
|
||
i: int | ||
i: object | ||
/ | ||
|
||
Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff. | ||
[clinic start generated code]*/ | ||
|
||
static PyObject * | ||
builtin_chr_impl(PyObject *module, int i) | ||
/*[clinic end generated code: output=c733afcd200afcb7 input=3f604ef45a70750d]*/ | ||
builtin_chr(PyObject *module, PyObject *i) | ||
/*[clinic end generated code: output=d34f25b8035a9b10 input=f919867f0ba2f496]*/ | ||
{ | ||
return PyUnicode_FromOrdinal(i); | ||
int ch = _PyLong_AsInt(i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to use |
||
if (ch == -1 && PyErr_Occurred()) { | ||
if (!PyErr_ExceptionMatches(PyExc_OverflowError)) { | ||
return NULL; | ||
} | ||
PyErr_Clear(); | ||
} | ||
return PyUnicode_FromOrdinal(ch); | ||
} | ||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
2**1000
. It is possible that once Python will run platform with 128-bit C long.