[New-bugs-announce] [issue32582] chr raises OverflowError

Uwe Kleine-König report at bugs.python.org
Wed Jan 17 09:32:06 EST 2018

New submission from Uwe Kleine-König <uwe+python at kleine-koenig.org>:


the description for chr (from https://docs.python.org/3/library/functions.html#chr) reads as:

        Return the string representing a character whose Unicode code
        point is the integer i. [...] The valid range for the argument
        is from 0 through 1,114,111 (0x10FFFF in base 16). ValueError
        will be raised if i is outside that range.

If however a value > 0x7fffffff (or < -0x80000000) is provided, the function raises an Overflow error:

        $ python3 -c 'print(chr(0x80000000))'
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
        OverflowError: signed integer is greater than maximum

This is either a documentation problem or (more like) an implementation issue. I attached a patch that fixes the issue for me. (I'm not sure however if I should call PyErr_Clear() before raising ValueError.)

components: Interpreter Core
files: chr-OverflowError.patch
keywords: patch
messages: 310178
nosy: ukl
priority: normal
severity: normal
status: open
title: chr raises OverflowError
versions: Python 3.6
Added file: https://bugs.python.org/file47390/chr-OverflowError.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list