Skip to content

Commit 48a2f8f

Browse files
committed
python#13054: sys.maxunicode is now always 0x10FFFF.
1 parent 506f592 commit 48a2f8f

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

Doc/library/sys.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,13 @@ always available.
625625

626626
.. data:: maxunicode
627627

628-
An integer giving the largest supported code point for a Unicode character. The
629-
value of this depends on the configuration option that specifies whether Unicode
630-
characters are stored as UCS-2 or UCS-4.
628+
An integer giving the value of the largest Unicode code point,
629+
i.e. ``1114111`` (``0x10FFFF`` in hexadecimal).
630+
631+
.. versionchanged:: 3.3
632+
Before :pep:`393`, :data:`sys.maxunicode` used to return either ``0xFFFF``
633+
or ``0x10FFFF``, depending on the configuration option that specified
634+
whether Unicode characters were stored as UCS-2 or UCS-4.
631635

632636

633637
.. data:: meta_path

Doc/whatsnew/3.3.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ PEP XXX: Stub
5555
=============
5656

5757

58+
PEP 393: Flexible String Representation
59+
=======================================
60+
61+
XXX Add list of changes introduced by :pep:`393` here:
62+
63+
* The value of :data:`sys.maxunicode` is now always ``1114111`` (``0x10FFFF``
64+
in hexadecimal). The :c:func:`PyUnicode_GetMax` function still returns
65+
either ``0xFFFF`` or ``0x10FFFF`` for backward compatibility, and it should
66+
not be used with the new Unicode API (see :issue:`13054`).
67+
68+
5869
Other Language Changes
5970
======================
6071

Lib/test/test_sys.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ def test_attributes(self):
447447

448448
self.assertIsInstance(sys.maxsize, int)
449449
self.assertIsInstance(sys.maxunicode, int)
450+
self.assertEqual(sys.maxunicode, 0x10FFFF)
450451
self.assertIsInstance(sys.platform, str)
451452
self.assertIsInstance(sys.prefix, str)
452453
self.assertIsInstance(sys.version, str)

Objects/unicodeobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ static unsigned char ascii_linebreak[] = {
207207
0, 0, 0, 0, 0, 0, 0, 0
208208
};
209209

210-
210+
/* The max unicode value is always 0x10FFFF while using the PEP-393 API.
211+
This function is kept for backward compatibility with the old API. */
211212
Py_UNICODE
212213
PyUnicode_GetMax(void)
213214
{

Python/sysmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ float_repr_style -- string indicating the style of repr() output for floats\n\
12611261
hexversion -- version information encoded as a single integer\n\
12621262
int_info -- a struct sequence with information about the int implementation.\n\
12631263
maxsize -- the largest supported length of containers.\n\
1264-
maxunicode -- the largest supported character\n\
1264+
maxunicode -- the value of the largest Unicode codepoint\n\
12651265
platform -- platform identifier\n\
12661266
prefix -- prefix used to find the Python library\n\
12671267
thread_info -- a struct sequence with information about the thread implementation.\n\
@@ -1536,7 +1536,7 @@ _PySys_Init(void)
15361536
SET_SYS_FROM_STRING("hash_info",
15371537
get_hash_info());
15381538
SET_SYS_FROM_STRING("maxunicode",
1539-
PyLong_FromLong(PyUnicode_GetMax()));
1539+
PyLong_FromLong(0x10FFFF));
15401540
SET_SYS_FROM_STRING("builtin_module_names",
15411541
list_builtin_module_names());
15421542
{

0 commit comments

Comments
 (0)