Skip to content

Commit ec34e1d

Browse files
Merge branch 'main' into zstd-ver
2 parents ada56cc + 27bd082 commit ec34e1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1282
-301
lines changed

Doc/howto/free-threading-extensions.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ You can use it to enable code that only runs under the free-threaded build::
2323
/* code that only runs in the free-threaded build */
2424
#endif
2525

26+
.. note::
27+
28+
On Windows, this macro is not defined automatically, but must be specified
29+
to the compiler when building. The :func:`sysconfig.get_config_var` function
30+
can be used to determine whether the current running interpreter had the
31+
macro defined.
32+
33+
2634
Module Initialization
2735
=====================
2836

Doc/library/multiprocessing.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,12 @@ object -- see :ref:`multiprocessing-managers`.
13691369
A solitary difference from its close analog exists: its ``acquire`` method's
13701370
first argument is named *block*, as is consistent with :meth:`Lock.acquire`.
13711371

1372+
.. method:: locked()
1373+
1374+
Return a boolean indicating whether this object is locked right now.
1375+
1376+
.. versionadded:: 3.14
1377+
13721378
.. note::
13731379
On macOS, this is indistinguishable from :class:`Semaphore` because
13741380
``sem_getvalue()`` is not implemented on that platform.
@@ -1521,6 +1527,12 @@ object -- see :ref:`multiprocessing-managers`.
15211527
A solitary difference from its close analog exists: its ``acquire`` method's
15221528
first argument is named *block*, as is consistent with :meth:`Lock.acquire`.
15231529

1530+
.. method:: locked()
1531+
1532+
Return a boolean indicating whether this object is locked right now.
1533+
1534+
.. versionadded:: 3.14
1535+
15241536
.. note::
15251537

15261538
On macOS, ``sem_timedwait`` is unsupported, so calling ``acquire()`` with

Doc/library/re.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,8 @@ Functions
991991
That way, separator components are always found at the same relative
992992
indices within the result list.
993993

994-
Empty matches for the pattern split the string only when not adjacent
995-
to a previous empty match.
994+
Adjacent empty matches are not possible, but an empty match can occur
995+
immediately after a non-empty match.
996996

997997
.. code:: pycon
998998
@@ -1095,9 +1095,12 @@ Functions
10951095

10961096
The optional argument *count* is the maximum number of pattern occurrences to be
10971097
replaced; *count* must be a non-negative integer. If omitted or zero, all
1098-
occurrences will be replaced. Empty matches for the pattern are replaced only
1099-
when not adjacent to a previous empty match, so ``sub('x*', '-', 'abxd')`` returns
1100-
``'-a-b--d-'``.
1098+
occurrences will be replaced.
1099+
1100+
Adjacent empty matches are not possible, but an empty match can occur
1101+
immediately after a non-empty match.
1102+
As a result, ``sub('x*', '-', 'abxd')`` returns ``'-a-b--d-'``
1103+
instead of ``'-a-b-d-'``.
11011104

11021105
.. index:: single: \g; in regular expressions
11031106

@@ -1128,8 +1131,7 @@ Functions
11281131
.. versionchanged:: 3.7
11291132
Unknown escapes in *repl* consisting of ``'\'`` and an ASCII letter
11301133
now are errors.
1131-
Empty matches for the pattern are replaced when adjacent to a previous
1132-
non-empty match.
1134+
An empty match can occur immediately after a non-empty match.
11331135

11341136
.. versionchanged:: 3.12
11351137
Group *id* can only contain ASCII digits.

Doc/whatsnew/3.14.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,12 @@ Kumar Aditya, Edgar Margffoy, and many others.
829829
Some of these contributors are employed by Meta, which has continued to provide
830830
significant engineering resources to support this project.
831831

832+
From 3.14, when compiling extension modules for the free-threaded build of
833+
CPython on Windows, the preprocessor variable ``Py_GIL_DISABLED`` now needs to
834+
be specified by the build backend, as it will no longer be determined
835+
automatically by the C compiler. For a running interpreter, the setting that
836+
was used at compile time can be found using :func:`sysconfig.get_config_var`.
837+
832838

833839
.. _whatsnew314-pyrepl-highlighting:
834840

Include/Python.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@
5959
# include <intrin.h> // __readgsqword()
6060
#endif
6161

62+
// Suppress known warnings in Python header files.
63+
#if defined(_MSC_VER)
64+
// Warning that alignas behaviour has changed. Doesn't affect us, because we
65+
// never relied on the old behaviour.
66+
#pragma warning(push)
67+
#pragma warning(disable: 5274)
68+
#endif
69+
6270
// Include Python header files
6371
#include "pyport.h"
6472
#include "pymacro.h"
@@ -138,4 +146,9 @@
138146
#include "cpython/pyfpe.h"
139147
#include "cpython/tracemalloc.h"
140148

149+
// Restore warning filter
150+
#ifdef _MSC_VER
151+
#pragma warning(pop)
152+
#endif
153+
141154
#endif /* !Py_PYTHON_H */

Include/internal/pycore_opcode_metadata.h

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/py_curses.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ static void **PyCurses_API;
109109
static const char catchall_ERR[] = "curses function returned ERR";
110110
static const char catchall_NULL[] = "curses function returned NULL";
111111

112+
#if defined(CURSES_MODULE) || defined(CURSES_PANEL_MODULE)
113+
/* Error messages shared by the curses package */
114+
# define CURSES_ERROR_FORMAT "%s() returned %s"
115+
# define CURSES_ERROR_VERBOSE_FORMAT "%s() (called by %s()) returned %s"
116+
# define CURSES_ERROR_MUST_CALL_FORMAT "must call %s() first"
117+
#endif
118+
112119
#ifdef __cplusplus
113120
}
114121
#endif

Lib/_pydatetime.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ def _parse_isoformat_time(tstr):
467467
hour, minute, second, microsecond = time_comps
468468
became_next_day = False
469469
error_from_components = False
470+
error_from_tz = None
470471
if (hour == 24):
471472
if all(time_comp == 0 for time_comp in time_comps[1:]):
472473
hour = 0
@@ -500,14 +501,22 @@ def _parse_isoformat_time(tstr):
500501
else:
501502
tzsign = -1 if tstr[tz_pos - 1] == '-' else 1
502503

503-
td = timedelta(hours=tz_comps[0], minutes=tz_comps[1],
504-
seconds=tz_comps[2], microseconds=tz_comps[3])
505-
506-
tzi = timezone(tzsign * td)
504+
try:
505+
# This function is intended to validate datetimes, but because
506+
# we restrict time zones to ±24h, it serves here as well.
507+
_check_time_fields(hour=tz_comps[0], minute=tz_comps[1],
508+
second=tz_comps[2], microsecond=tz_comps[3],
509+
fold=0)
510+
except ValueError as e:
511+
error_from_tz = e
512+
else:
513+
td = timedelta(hours=tz_comps[0], minutes=tz_comps[1],
514+
seconds=tz_comps[2], microseconds=tz_comps[3])
515+
tzi = timezone(tzsign * td)
507516

508517
time_comps.append(tzi)
509518

510-
return time_comps, became_next_day, error_from_components
519+
return time_comps, became_next_day, error_from_components, error_from_tz
511520

512521
# tuple[int, int, int] -> tuple[int, int, int] version of date.fromisocalendar
513522
def _isoweek_to_gregorian(year, week, day):
@@ -1633,9 +1642,21 @@ def fromisoformat(cls, time_string):
16331642
time_string = time_string.removeprefix('T')
16341643

16351644
try:
1636-
return cls(*_parse_isoformat_time(time_string)[0])
1637-
except Exception:
1638-
raise ValueError(f'Invalid isoformat string: {time_string!r}')
1645+
time_components, _, error_from_components, error_from_tz = (
1646+
_parse_isoformat_time(time_string)
1647+
)
1648+
except ValueError:
1649+
raise ValueError(
1650+
f'Invalid isoformat string: {time_string!r}') from None
1651+
else:
1652+
if error_from_tz:
1653+
raise error_from_tz
1654+
if error_from_components:
1655+
raise ValueError(
1656+
"Minute, second, and microsecond must be 0 when hour is 24"
1657+
)
1658+
1659+
return cls(*time_components)
16391660

16401661
def strftime(self, format):
16411662
"""Format using strftime(). The date part of the timestamp passed
@@ -1947,11 +1968,16 @@ def fromisoformat(cls, date_string):
19471968

19481969
if tstr:
19491970
try:
1950-
time_components, became_next_day, error_from_components = _parse_isoformat_time(tstr)
1971+
(time_components,
1972+
became_next_day,
1973+
error_from_components,
1974+
error_from_tz) = _parse_isoformat_time(tstr)
19511975
except ValueError:
19521976
raise ValueError(
19531977
f'Invalid isoformat string: {date_string!r}') from None
19541978
else:
1979+
if error_from_tz:
1980+
raise error_from_tz
19551981
if error_from_components:
19561982
raise ValueError("minute, second, and microsecond must be 0 when hour is 24")
19571983

Lib/_pyrepl/simple_interact.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ def run_multiline_interactive_console(
110110
more_lines = functools.partial(_more_lines, console)
111111
input_n = 0
112112

113+
_is_x_showrefcount_set = sys._xoptions.get("showrefcount")
114+
_is_pydebug_build = hasattr(sys, "gettotalrefcount")
115+
show_ref_count = _is_x_showrefcount_set and _is_pydebug_build
116+
113117
def maybe_run_command(statement: str) -> bool:
114118
statement = statement.strip()
115119
if statement in console.locals or statement not in REPL_COMMANDS:
@@ -167,3 +171,8 @@ def maybe_run_command(statement: str) -> bool:
167171
except:
168172
console.showtraceback()
169173
console.resetbuffer()
174+
if show_ref_count:
175+
console.write(
176+
f"[{sys.gettotalrefcount()} refs,"
177+
f" {sys.getallocatedblocks()} blocks]\n"
178+
)

Lib/_pyrepl/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ def from_re(cls, m: Match[str], group: int | str) -> Self:
4141

4242
@classmethod
4343
def from_token(cls, token: TI, line_len: list[int]) -> Self:
44+
end_offset = -1
45+
if (token.type in {T.FSTRING_MIDDLE, T.TSTRING_MIDDLE}
46+
and token.string.endswith(("{", "}"))):
47+
# gh-134158: a visible trailing brace comes from a double brace in input
48+
end_offset += 1
49+
4450
return cls(
4551
line_len[token.start[0] - 1] + token.start[1],
46-
line_len[token.end[0] - 1] + token.end[1] - 1,
52+
line_len[token.end[0] - 1] + token.end[1] + end_offset,
4753
)
4854

4955

0 commit comments

Comments
 (0)