Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Doc/builtins/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2157,7 +2157,7 @@ expression support in the :mod:`re` module).

The casefolding algorithm is `described in section 3.13.3 'Default Case
Folding' of the Unicode Standard
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G53253>`__.
<https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-3/#G53253>`__.

.. versionadded:: 3.3

Expand Down Expand Up @@ -2398,7 +2398,7 @@ expression support in the :mod:`re` module).
property being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is different
from the `Alphabetic property defined in section 4.10 'Letters, Alphabetic, and
Ideographic' of the Unicode Standard
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-4/#G91002>`__.
<https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-4/#G91002>`__.
For example:

.. doctest::
Expand Down Expand Up @@ -2664,7 +2664,7 @@ expression support in the :mod:`re` module).

The lowercasing algorithm used is `described in section 3.13.2 'Default Case
Conversion' of the Unicode Standard
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G34078>`__.
<https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-3/#G34078>`__.


.. method:: str.lstrip(chars=None, /)
Expand Down Expand Up @@ -3176,7 +3176,7 @@ expression support in the :mod:`re` module).

The uppercasing algorithm used is `described in section 3.13.2 'Default Case
Conversion' of the Unicode Standard
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G34078>`__.
<https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-3/#G34078>`__.


.. method:: str.zfill(width, /)
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/re.rst
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ character ``'$'``.

Matches ``[0-9]`` if the :py:const:`~re.ASCII` flag is used.

__ https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-4/#G124142
__ https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-4/#G124142

For 8-bit (bytes) patterns:
Matches any decimal digit in the ASCII character set;
Expand Down
10 changes: 5 additions & 5 deletions Doc/library/unicodedata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

This module provides access to the Unicode Character Database (UCD) which
defines character properties for all Unicode characters. The data contained in
this database is compiled from the `UCD version 17.0.0
<https://www.unicode.org/Public/17.0.0/ucd>`_.
this database is compiled from the `UCD version 18.0.0
<https://www.unicode.org/Public/18.0.0/ucd>`_.

The module uses the same names and symbols as defined by Unicode
Standard Annex #44, `"Unicode Character Database"
Expand Down Expand Up @@ -170,7 +170,7 @@ Standard Annex #44, `"Unicode Character Database"
.. function:: block(chr, /)

Returns the `block
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G64189>`_
<https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-3/#G64189>`_
assigned to the character *chr*. For example::

>>> unicodedata.block('S')
Expand Down Expand Up @@ -326,6 +326,6 @@ In addition, the module exposes the following constants:

.. rubric:: Footnotes

.. [#] https://www.unicode.org/Public/17.0.0/ucd/NameAliases.txt
.. [#] https://www.unicode.org/Public/18.0.0/ucd/NameAliases.txt

.. [#] https://www.unicode.org/Public/17.0.0/ucd/NamedSequences.txt
.. [#] https://www.unicode.org/Public/18.0.0/ucd/NamedSequences.txt
6 changes: 3 additions & 3 deletions Doc/reference/lexical_analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ Unicode categories use the version of the Unicode Character Database as
included in the :mod:`unicodedata` module.

.. _UAX-31: https://www.unicode.org/reports/tr31/
.. _PropList.txt: https://www.unicode.org/Public/17.0.0/ucd/PropList.txt
.. _DerivedCoreProperties.txt: https://www.unicode.org/Public/17.0.0/ucd/DerivedCoreProperties.txt
.. _PropList.txt: https://www.unicode.org/Public/18.0.0/ucd/PropList.txt
.. _DerivedCoreProperties.txt: https://www.unicode.org/Public/18.0.0/ucd/DerivedCoreProperties.txt
.. _normalization form: https://www.unicode.org/reports/tr15/#Norm_Forms

.. seealso::
Expand Down Expand Up @@ -916,7 +916,7 @@ with the given *name*::
This sequence cannot appear in :ref:`bytes literals <bytes-literal>`.

.. versionchanged:: 3.3
Support for `name aliases <https://www.unicode.org/Public/17.0.0/ucd/NameAliases.txt>`__
Support for `name aliases <https://www.unicode.org/Public/18.0.0/ucd/NameAliases.txt>`__
has been added.

.. _string-escape-long-hex:
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,11 @@ tkinter
with no unit suffix to :class:`int` or :class:`float`.
(Contributed by Serhiy Storchaka in :gh:`153513`.)

unicodedata
-----------

* The Unicode database has been updated to Unicode 18.0.0.

xml
---

Expand Down
8 changes: 6 additions & 2 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1181,8 +1181,12 @@ invalid_arguments:
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, _PyPegen_get_last_comprehension_item(PyPegen_last_item(b, comprehension_ty)), "Generator expression must be parenthesized") }
| a=args ',' args { _PyPegen_arguments_parsing_error(p, a) }
invalid_kwarg:
| a[Token*]=('True'|'False'|'None') b='=' {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to %s", PyBytes_AS_STRING(a->bytes)) }
| a='True' b='=' {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to True") }
| a='False' b='=' {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to False") }
| a='None' b='=' {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to None") }
| a=NAME b='=' expression for_if_clauses {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?")}
| !(NAME '=') a=expression b='=' {
Expand Down
4 changes: 4 additions & 0 deletions Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,10 @@ def main():
if filename and os.path.isfile(filename):
shell.interp.execfile(filename)
if cmd or script:
# Let the startup file finish first: the command or script
# is to run after it, in its namespace (gh-68453).
while shell.executing:
root.update()
shell.interp.runcommand("""if 1:
import sys as _sys
_sys.argv = {!r}
Expand Down
6 changes: 3 additions & 3 deletions Lib/re/_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
# CATEGORY_DIGIT matches Nd (but, like \d, is restricted to ASCII under the
# ASCII flag). The gc group memberships (L = Lu|Ll|Lt|Lm|Lo, N = Nd|Nl|No)
# are given by the Unicode Standard 4.5, Table 4-4 "General_Category Values"
# (https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-4/#G124142)
# (https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-4/#G124142)
# and listed in
# https://www.unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt
# The compound categories Lu, N, Lm, Nl, No, Cf, Z, Zs, C and Cn are
Expand All @@ -127,7 +127,7 @@
# (private use) and the single code points Zl and Zp. Cc, Cs and Co are the
# control codes, surrogate and private-use areas, fixed by the Unicode
# Standard 23.1, 23.6 and 23.5:
# https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-23/
# https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-23/
# All five are listed in
# https://www.unicode.org/Public/UCD/latest/ucd/extracted/DerivedGeneralCategory.txt
_CC_RANGES = [(0x00, 0x1F), (0x7F, 0x9F)]
Expand Down Expand Up @@ -174,7 +174,7 @@ def _analytic_ranges():
# normalised.
# Noncharacter_Code_Point: U+FDD0..FDEF and the last two of every plane,
# permanently reserved (the Unicode Standard 23.7, "Noncharacters":
# https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-23/).
# https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-23/).
noncharacter = [(0xFDD0, 0xFDEF)]
noncharacter += [(plane | 0xFFFE, plane | 0xFFFF)
for plane in range(0, MAXUNICODE + 1, 0x10000)]
Expand Down
11 changes: 8 additions & 3 deletions Lib/stringprep.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# when unicodedata is modified to ensure conformant behavior.
import unicodedata

assert unicodedata.unidata_version == '17.0.0'
assert unicodedata.unidata_version == '18.0.0'

from unicodedata import ucd_3_2_0 as unicodedata_320

Expand Down Expand Up @@ -192,7 +192,8 @@ def in_table_b1(code):
0xa7c5:'\ua7c5', 0xa7c6:'\ua7c6', 0xa7c7:'\ua7c7', 0xa7c9:'\ua7c9',
0xa7cb:'\ua7cb', 0xa7cc:'\ua7cc', 0xa7ce:'\ua7ce', 0xa7d0:'\ua7d0',
0xa7d2:'\ua7d2', 0xa7d4:'\ua7d4', 0xa7d6:'\ua7d6', 0xa7d8:'\ua7d8',
0xa7da:'\ua7da', 0xa7dc:'\ua7dc', 0xa7f5:'\ua7f5', 0xfb00:'ff',
0xa7da:'\ua7da', 0xa7dc:'\ua7dc', 0xa7dd:'\ua7dd', 0xa7e2:'\ua7e2',
0xa7f5:'\ua7f5', 0xab6c:'\uab6c', 0xab6d:'\uab6d', 0xfb00:'ff',
0xfb01:'fi', 0xfb02:'fl', 0xfb03:'ffi', 0xfb04:'ffl',
0xfb05:'st', 0xfb06:'st', 0xfb13:'\u0574\u0576', 0xfb14:'\u0574\u0565',
0xfb15:'\u0574\u056b', 0xfb16:'\u057e\u0576', 0xfb17:'\u0574\u056d', 0x10426:'\U00010426',
Expand Down Expand Up @@ -366,7 +367,11 @@ def in_table_b1(code):
0x1d79c:'\u03bd', 0x1d79d:'\u03be', 0x1d79e:'\u03bf', 0x1d79f:'\u03c0',
0x1d7a0:'\u03c1', 0x1d7a1:'\u03b8', 0x1d7a2:'\u03c3', 0x1d7a3:'\u03c4',
0x1d7a4:'\u03c5', 0x1d7a5:'\u03c6', 0x1d7a6:'\u03c7', 0x1d7a7:'\u03c8',
0x1d7a8:'\u03c9', 0x1d7bb:'\u03c3', 0x1e900:'\U0001e900', 0x1e901:'\U0001e901',
0x1d7a8:'\u03c9', 0x1d7bb:'\u03c3', 0x1df40:'\U0001df40', 0x1df48:'\U0001df48',
0x1df4a:'\U0001df4a', 0x1df4d:'\U0001df4d', 0x1df51:'\U0001df51', 0x1df68:'\U0001df68',
0x1df6a:'\U0001df6a', 0x1df6c:'\U0001df6c', 0x1df6e:'\U0001df6e', 0x1df72:'\U0001df72',
0x1df74:'\U0001df74', 0x1df76:'\U0001df76', 0x1df78:'\U0001df78', 0x1df7a:'\U0001df7a',
0x1df7c:'\U0001df7c', 0x1df7e:'\U0001df7e', 0x1e900:'\U0001e900', 0x1e901:'\U0001e901',
0x1e902:'\U0001e902', 0x1e903:'\U0001e903', 0x1e904:'\U0001e904', 0x1e905:'\U0001e905',
0x1e906:'\U0001e906', 0x1e907:'\U0001e907', 0x1e908:'\U0001e908', 0x1e909:'\U0001e909',
0x1e90a:'\U0001e90a', 0x1e90b:'\U0001e90b', 0x1e90c:'\U0001e90c', 0x1e90d:'\U0001e90d',
Expand Down
62 changes: 50 additions & 12 deletions Lib/test/support/os_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import warnings

from test import support
if support.MS_WINDOWS:
import _winapi


# Filename used for testing
Expand Down Expand Up @@ -854,36 +856,72 @@ def __new__(mcls, name, bases, dct, *, source_date_epoch):

try:
if support.MS_WINDOWS:
import ctypes
import ctypes.util
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)

ERROR_FILE_NOT_FOUND = 2
DDD_REMOVE_DEFINITION = 2
DDD_EXACT_MATCH_ON_REMOVE = 4
DDD_NO_BROADCAST_SYSTEM = 8
else:
raise AttributeError
except (ImportError, AttributeError):
def subst_drive(path):
raise unittest.SkipTest('ctypes or kernel32 is not available')

def handle_count():
return 0
else:
ERROR_FILE_NOT_FOUND = 2
DDD_REMOVE_DEFINITION = 2
DDD_EXACT_MATCH_ON_REMOVE = 4
DDD_NO_BROADCAST_SYSTEM = 8

@ctypes.util.wrap_dll_function(kernel32)
def DefineDosDeviceW(
dwFlags: ctypes.wintypes.DWORD,
lpDeviceName: ctypes.c_wchar_p,
lpTargetPath: ctypes.c_wchar_p,
) -> ctypes.wintypes.BOOL:
pass

@ctypes.util.wrap_dll_function(kernel32)
def QueryDosDeviceW(
lpDeviceName: ctypes.c_wchar_p,
lpTargetPath: ctypes.c_wchar_p,
ucchMax: ctypes.wintypes.DWORD,
) -> ctypes.wintypes.DWORD:
pass

@contextlib.contextmanager
def subst_drive(path):
"""Temporarily yield a substitute drive for a given path."""
for c in reversed(string.ascii_uppercase):
drive = f'{c}:'
if (not kernel32.QueryDosDeviceW(drive, None, 0) and
if (not QueryDosDeviceW(drive, None, 0) and
ctypes.get_last_error() == ERROR_FILE_NOT_FOUND):
break
else:
raise unittest.SkipTest('no available logical drive')
if not kernel32.DefineDosDeviceW(
DDD_NO_BROADCAST_SYSTEM, drive, path):

if not DefineDosDeviceW(DDD_NO_BROADCAST_SYSTEM, drive, path):
raise ctypes.WinError(ctypes.get_last_error())

try:
yield drive
finally:
if not kernel32.DefineDosDeviceW(
DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE,
drive, path):
flags = DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE
if not DefineDosDeviceW(flags, drive, path):
raise ctypes.WinError(ctypes.get_last_error())

@ctypes.util.wrap_dll_function(kernel32)
def GetProcessHandleCount(khProcess: ctypes.wintypes.HANDLE,
pdwHandleCount: ctypes.wintypes.LPDWORD) -> ctypes.wintypes.BOOL:
pass

del kernel32

def handle_count():
# Pseudo-handle that doesn't need to be closed
hproc = _winapi.GetCurrentProcess()

handle_count = ctypes.wintypes.DWORD()
if not GetProcessHandleCount(hproc, ctypes.byref(handle_count)):
raise ctypes.WinError(ctypes.get_last_error())

return handle_count.value
29 changes: 2 additions & 27 deletions Lib/test/test_os/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,28 +457,7 @@ def test_unlink_removes_junction(self):
class Win32NtTests(unittest.TestCase):
def test_getfinalpathname_handles(self):
nt = import_helper.import_module('nt')
ctypes = import_helper.import_module('ctypes')
# Ruff false positive -- it thinks we're redefining `ctypes` here
import ctypes.wintypes # noqa: F811

kernel = ctypes.WinDLL('Kernel32.dll', use_last_error=True)
@ctypes.util.wrap_dll_function(kernel)
def GetCurrentProcess() -> ctypes.wintypes.HANDLE:
pass

@ctypes.util.wrap_dll_function(kernel)
def GetProcessHandleCount(khProcess: ctypes.wintypes.HANDLE,
pdwHandleCount: ctypes.wintypes.LPDWORD) -> ctypes.wintypes.BOOL:
pass

# This is a pseudo-handle that doesn't need to be closed
hproc = GetCurrentProcess()

handle_count = ctypes.wintypes.DWORD()
ok = GetProcessHandleCount(hproc, ctypes.byref(handle_count))
self.assertEqual(1, ok)

before_count = handle_count.value
before_count = os_helper.handle_count()

# The first two test the error path, __file__ tests the success path
filenames = [
Expand All @@ -500,11 +479,7 @@ def GetProcessHandleCount(khProcess: ctypes.wintypes.HANDLE,
except Exception:
pass

ok = kernel.GetProcessHandleCount(hproc, ctypes.byref(handle_count))
self.assertEqual(1, ok)

handle_delta = handle_count.value - before_count

handle_delta = os_helper.handle_count() - before_count
self.assertEqual(0, handle_delta)

@support.requires_subprocess()
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
from test.support import socket_helper
from test.support import warnings_helper

if support.MS_WINDOWS:
import _winapi


TESTFN = os_helper.TESTFN


Expand Down Expand Up @@ -624,6 +628,20 @@ def test_fd_count(self):
os.close(fd)
self.assertEqual(more - start, 1)

@unittest.skipUnless(support.MS_WINDOWS, "test specific to Windows")
def test_handle_count(self):
start = os_helper.handle_count()
handle = _winapi.CreateFile(
__file__, _winapi.GENERIC_READ,
0, _winapi.NULL,
_winapi.OPEN_EXISTING,
0, _winapi.NULL)
try:
more = os_helper.handle_count()
finally:
_winapi.CloseHandle(handle)
self.assertEqual(more - start, 1)

def check_print_warning(self, msg, expected):
stderr = io.StringIO()
with support.swap_attr(support.print_warning, 'orig_stderr', stderr):
Expand Down
Loading
Loading