Skip to content

Commit 5e1b65f

Browse files
committed
Merge branch 'main' into pythongh-126148-authority
2 parents 1b2d2e0 + 307c633 commit 5e1b65f

26 files changed

+222
-215
lines changed

Doc/c-api/init.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,11 @@ function. You can create and destroy them using the following functions:
17381738
.check_multi_interp_extensions = 1,
17391739
.gil = PyInterpreterConfig_OWN_GIL,
17401740
};
1741-
PyThreadState *tstate = Py_NewInterpreterFromConfig(&config);
1741+
PyThreadState *tstate = NULL;
1742+
PyStatus status = Py_NewInterpreterFromConfig(&tstate, &config);
1743+
if (PyStatus_Exception(status)) {
1744+
Py_ExitStatusException(status);
1745+
}
17421746
17431747
Note that the config is used only briefly and does not get modified.
17441748
During initialization the config's values are converted into various
@@ -2466,7 +2470,7 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
24662470
24672471
{
24682472
PyCriticalSection2 _py_cs2;
2469-
PyCriticalSection_Begin2(&_py_cs2, (PyObject*)(a), (PyObject*)(b))
2473+
PyCriticalSection2_Begin(&_py_cs2, (PyObject*)(a), (PyObject*)(b))
24702474
24712475
In the default build, this macro expands to ``{``.
24722476
@@ -2478,7 +2482,7 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
24782482
24792483
In the free-threaded build, this macro expands to::
24802484
2481-
PyCriticalSection_End2(&_py_cs2);
2485+
PyCriticalSection2_End(&_py_cs2);
24822486
}
24832487
24842488
In the default build, this macro expands to ``}``.

Doc/library/argparse.rst

+9-10
Original file line numberDiff line numberDiff line change
@@ -1926,11 +1926,10 @@ Argument groups
19261926
Note that any arguments not in your user-defined groups will end up back
19271927
in the usual "positional arguments" and "optional arguments" sections.
19281928

1929-
.. versionchanged:: 3.11
1930-
Calling :meth:`add_argument_group` on an argument group is deprecated.
1931-
This feature was never supported and does not always work correctly.
1932-
The function exists on the API by accident through inheritance and
1933-
will be removed in the future.
1929+
.. deprecated-removed:: 3.11 3.14
1930+
Calling :meth:`add_argument_group` on an argument group now raises an
1931+
exception. This nesting was never supported, often failed to work
1932+
correctly, and was unintentionally exposed through inheritance.
19341933

19351934
.. deprecated:: 3.14
19361935
Passing prefix_chars_ to :meth:`add_argument_group`
@@ -1993,11 +1992,11 @@ Mutual exclusion
19931992
--foo FOO foo help
19941993
--bar BAR bar help
19951994

1996-
.. versionchanged:: 3.11
1997-
Calling :meth:`add_argument_group` or :meth:`add_mutually_exclusive_group`
1998-
on a mutually exclusive group is deprecated. These features were never
1999-
supported and do not always work correctly. The functions exist on the
2000-
API by accident through inheritance and will be removed in the future.
1995+
.. deprecated-removed:: 3.11 3.14
1996+
Calling :meth:`add_argument_group` or :meth:`add_mutually_exclusive_group`
1997+
on a mutually exclusive group now raises an exception. This nesting was
1998+
never supported, often failed to work correctly, and was unintentionally
1999+
exposed through inheritance.
20012000

20022001

20032002
Parser defaults

Doc/library/urllib.request.rst

+19-7
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,15 @@ The :mod:`urllib.request` module defines the following functions:
148148

149149
.. function:: pathname2url(path)
150150

151-
Convert the pathname *path* from the local syntax for a path to the form used in
152-
the path component of a URL. This does not produce a complete URL. The return
153-
value will already be quoted using the :func:`~urllib.parse.quote` function.
151+
Convert the given local path to a ``file:`` URL. This function uses
152+
:func:`~urllib.parse.quote` function to encode the path. For historical
153+
reasons, the return value omits the ``file:`` scheme prefix. This example
154+
shows the function being used on Windows::
155+
156+
>>> from urllib.request import pathname2url
157+
>>> path = 'C:\\Program Files'
158+
>>> 'file:' + pathname2url(path)
159+
'file:///C:/Program%20Files'
154160

155161
.. versionchanged:: 3.14
156162
Paths beginning with a slash are converted to URLs with authority
@@ -163,11 +169,17 @@ The :mod:`urllib.request` module defines the following functions:
163169
:exc:`OSError` exception to be raised on Windows.
164170

165171

166-
.. function:: url2pathname(path)
172+
.. function:: url2pathname(url)
173+
174+
Convert the given ``file:`` URL to a local path. This function uses
175+
:func:`~urllib.parse.unquote` to decode the URL. For historical reasons,
176+
the given value *must* omit the ``file:`` scheme prefix. This example shows
177+
the function being used on Windows::
167178

168-
Convert the path component *path* from a percent-encoded URL to the local syntax for a
169-
path. This does not accept a complete URL. This function uses
170-
:func:`~urllib.parse.unquote` to decode *path*.
179+
>>> from urllib.request import url2pathname
180+
>>> url = 'file:///C:/Program%20Files'
181+
>>> url2pathname(url.removeprefix('file:'))
182+
'C:\\Program Files'
171183

172184
.. versionchanged:: 3.14
173185
Windows drive letters are no longer converted to uppercase.

Doc/whatsnew/3.11.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ Replaced opcodes
16701670
| | | for each direction |
16711671
| | | |
16721672
+------------------------------------+------------------------------------+-----------------------------------------+
1673-
| | :opcode:`!SETUP_WITH` | :opcode:`BEFORE_WITH` | :keyword:`with` block setup |
1673+
| | :opcode:`!SETUP_WITH` | :opcode:`!BEFORE_WITH` | :keyword:`with` block setup |
16741674
| | :opcode:`!SETUP_ASYNC_WITH` | | |
16751675
+------------------------------------+------------------------------------+-----------------------------------------+
16761676

Doc/whatsnew/3.14.rst

+8
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,14 @@ argparse
641641
of :class:`!argparse.BooleanOptionalAction`.
642642
They were deprecated since 3.12.
643643

644+
* Calling :meth:`~argparse.ArgumentParser.add_argument_group` on an argument
645+
group, and calling :meth:`~argparse.ArgumentParser.add_argument_group` or
646+
:meth:`~argparse.ArgumentParser.add_mutually_exclusive_group` on a mutually
647+
exclusive group now raise exceptions. This nesting was never supported,
648+
often failed to work correctly, and was unintentionally exposed through
649+
inheritance. This functionality has been deprecated since Python 3.11.
650+
(Contributed by Savannah Ostrowski in :gh:`127186`.)
651+
644652
ast
645653
---
646654

Doc/whatsnew/3.4.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ Other Improvements
19791979
now works correctly (previously it silently returned the first python
19801980
module in the file). (Contributed by Václav Šmilauer in :issue:`16421`.)
19811981

1982-
* A new opcode, :opcode:`LOAD_CLASSDEREF`, has been added to fix a bug in the
1982+
* A new opcode, :opcode:`!LOAD_CLASSDEREF`, has been added to fix a bug in the
19831983
loading of free variables in class bodies that could be triggered by certain
19841984
uses of :ref:`__prepare__ <prepare>`. (Contributed by Benjamin Peterson in
19851985
:issue:`17853`.)

Doc/whatsnew/3.6.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -2366,27 +2366,27 @@ There have been several major changes to the :term:`bytecode` in Python 3.6.
23662366
(Contributed by Demur Rumed with input and reviews from
23672367
Serhiy Storchaka and Victor Stinner in :issue:`26647` and :issue:`28050`.)
23682368

2369-
* The new :opcode:`FORMAT_VALUE` and :opcode:`BUILD_STRING` opcodes as part
2369+
* The new :opcode:`!FORMAT_VALUE` and :opcode:`BUILD_STRING` opcodes as part
23702370
of the :ref:`formatted string literal <whatsnew36-pep498>` implementation.
23712371
(Contributed by Eric Smith in :issue:`25483` and
23722372
Serhiy Storchaka in :issue:`27078`.)
23732373

2374-
* The new :opcode:`BUILD_CONST_KEY_MAP` opcode to optimize the creation
2374+
* The new :opcode:`!BUILD_CONST_KEY_MAP` opcode to optimize the creation
23752375
of dictionaries with constant keys.
23762376
(Contributed by Serhiy Storchaka in :issue:`27140`.)
23772377

23782378
* The function call opcodes have been heavily reworked for better performance
23792379
and simpler implementation.
2380-
The :opcode:`MAKE_FUNCTION`, :opcode:`CALL_FUNCTION`,
2381-
:opcode:`CALL_FUNCTION_KW` and :opcode:`BUILD_MAP_UNPACK_WITH_CALL` opcodes
2380+
The :opcode:`MAKE_FUNCTION`, :opcode:`!CALL_FUNCTION`,
2381+
:opcode:`!CALL_FUNCTION_KW` and :opcode:`!BUILD_MAP_UNPACK_WITH_CALL` opcodes
23822382
have been modified, the new :opcode:`CALL_FUNCTION_EX` and
2383-
:opcode:`BUILD_TUPLE_UNPACK_WITH_CALL` have been added, and
2383+
:opcode:`!BUILD_TUPLE_UNPACK_WITH_CALL` have been added, and
23842384
``CALL_FUNCTION_VAR``, ``CALL_FUNCTION_VAR_KW`` and ``MAKE_CLOSURE`` opcodes
23852385
have been removed.
23862386
(Contributed by Demur Rumed in :issue:`27095`, and Serhiy Storchaka in
23872387
:issue:`27213`, :issue:`28257`.)
23882388

2389-
* The new :opcode:`SETUP_ANNOTATIONS` and :opcode:`STORE_ANNOTATION` opcodes
2389+
* The new :opcode:`SETUP_ANNOTATIONS` and :opcode:`!STORE_ANNOTATION` opcodes
23902390
have been added to support the new :term:`variable annotation` syntax.
23912391
(Contributed by Ivan Levkivskyi in :issue:`27985`.)
23922392

Doc/whatsnew/3.7.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2476,10 +2476,10 @@ avoiding possible problems use new functions :c:func:`PySlice_Unpack` and
24762476
CPython bytecode changes
24772477
------------------------
24782478

2479-
There are two new opcodes: :opcode:`LOAD_METHOD` and :opcode:`CALL_METHOD`.
2479+
There are two new opcodes: :opcode:`LOAD_METHOD` and :opcode:`!CALL_METHOD`.
24802480
(Contributed by Yury Selivanov and INADA Naoki in :issue:`26110`.)
24812481

2482-
The :opcode:`STORE_ANNOTATION` opcode has been removed.
2482+
The :opcode:`!STORE_ANNOTATION` opcode has been removed.
24832483
(Contributed by Mark Shannon in :issue:`32550`.)
24842484

24852485

Doc/whatsnew/3.8.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -2152,11 +2152,11 @@ CPython bytecode changes
21522152
cleaning-up code for :keyword:`break`, :keyword:`continue` and
21532153
:keyword:`return`.
21542154

2155-
Removed opcodes :opcode:`BREAK_LOOP`, :opcode:`CONTINUE_LOOP`,
2156-
:opcode:`SETUP_LOOP` and :opcode:`SETUP_EXCEPT`. Added new opcodes
2157-
:opcode:`ROT_FOUR`, :opcode:`BEGIN_FINALLY`, :opcode:`CALL_FINALLY` and
2158-
:opcode:`POP_FINALLY`. Changed the behavior of :opcode:`END_FINALLY`
2159-
and :opcode:`WITH_CLEANUP_START`.
2155+
Removed opcodes :opcode:`!BREAK_LOOP`, :opcode:`!CONTINUE_LOOP`,
2156+
:opcode:`!SETUP_LOOP` and :opcode:`!SETUP_EXCEPT`. Added new opcodes
2157+
:opcode:`!ROT_FOUR`, :opcode:`!BEGIN_FINALLY`, :opcode:`!CALL_FINALLY` and
2158+
:opcode:`!POP_FINALLY`. Changed the behavior of :opcode:`!END_FINALLY`
2159+
and :opcode:`!WITH_CLEANUP_START`.
21602160

21612161
(Contributed by Mark Shannon, Antoine Pitrou and Serhiy Storchaka in
21622162
:issue:`17611`.)

Doc/whatsnew/3.9.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ Changes in the C API
12031203
CPython bytecode changes
12041204
------------------------
12051205

1206-
* The :opcode:`LOAD_ASSERTION_ERROR` opcode was added for handling the
1206+
* The :opcode:`!LOAD_ASSERTION_ERROR` opcode was added for handling the
12071207
:keyword:`assert` statement. Previously, the assert statement would not work
12081208
correctly if the :exc:`AssertionError` exception was being shadowed.
12091209
(Contributed by Zackery Spytz in :issue:`34880`.)

Lib/argparse.py

+3-17
Original file line numberDiff line numberDiff line change
@@ -1709,14 +1709,7 @@ def _remove_action(self, action):
17091709
self._group_actions.remove(action)
17101710

17111711
def add_argument_group(self, *args, **kwargs):
1712-
import warnings
1713-
warnings.warn(
1714-
"Nesting argument groups is deprecated.",
1715-
category=DeprecationWarning,
1716-
stacklevel=2
1717-
)
1718-
return super().add_argument_group(*args, **kwargs)
1719-
1712+
raise ValueError('argument groups cannot be nested')
17201713

17211714
class _MutuallyExclusiveGroup(_ArgumentGroup):
17221715

@@ -1737,15 +1730,8 @@ def _remove_action(self, action):
17371730
self._container._remove_action(action)
17381731
self._group_actions.remove(action)
17391732

1740-
def add_mutually_exclusive_group(self, *args, **kwargs):
1741-
import warnings
1742-
warnings.warn(
1743-
"Nesting mutually exclusive groups is deprecated.",
1744-
category=DeprecationWarning,
1745-
stacklevel=2
1746-
)
1747-
return super().add_mutually_exclusive_group(*args, **kwargs)
1748-
1733+
def add_mutually_exclusive_group(self, **kwargs):
1734+
raise ValueError('mutually exclusive groups cannot be nested')
17491735

17501736
def _prog_name(prog=None):
17511737
if prog is not None:

Lib/test/test_argparse.py

+15-68
Original file line numberDiff line numberDiff line change
@@ -2997,6 +2997,13 @@ def test_group_prefix_chars_default(self):
29972997
self.assertEqual(msg, str(cm.warning))
29982998
self.assertEqual(cm.filename, __file__)
29992999

3000+
def test_nested_argument_group(self):
3001+
parser = argparse.ArgumentParser()
3002+
g = parser.add_argument_group()
3003+
self.assertRaisesRegex(ValueError,
3004+
'argument groups cannot be nested',
3005+
g.add_argument_group)
3006+
30003007
# ===================
30013008
# Parent parser tests
30023009
# ===================
@@ -3297,6 +3304,14 @@ def test_empty_group(self):
32973304
with self.assertRaises(ValueError):
32983305
parser.parse_args(['-h'])
32993306

3307+
def test_nested_mutex_groups(self):
3308+
parser = argparse.ArgumentParser(prog='PROG')
3309+
g = parser.add_mutually_exclusive_group()
3310+
g.add_argument("--spam")
3311+
self.assertRaisesRegex(ValueError,
3312+
'mutually exclusive groups cannot be nested',
3313+
g.add_mutually_exclusive_group)
3314+
33003315
class MEMixin(object):
33013316

33023317
def test_failures_when_not_required(self):
@@ -3664,55 +3679,6 @@ def get_parser(self, required):
36643679
-c c help
36653680
'''
36663681

3667-
class TestMutuallyExclusiveNested(MEMixin, TestCase):
3668-
3669-
# Nesting mutually exclusive groups is an undocumented feature
3670-
# that came about by accident through inheritance and has been
3671-
# the source of many bugs. It is deprecated and this test should
3672-
# eventually be removed along with it.
3673-
3674-
def get_parser(self, required):
3675-
parser = ErrorRaisingArgumentParser(prog='PROG')
3676-
group = parser.add_mutually_exclusive_group(required=required)
3677-
group.add_argument('-a')
3678-
group.add_argument('-b')
3679-
with warnings.catch_warnings():
3680-
warnings.simplefilter('ignore', DeprecationWarning)
3681-
group2 = group.add_mutually_exclusive_group(required=required)
3682-
group2.add_argument('-c')
3683-
group2.add_argument('-d')
3684-
with warnings.catch_warnings():
3685-
warnings.simplefilter('ignore', DeprecationWarning)
3686-
group3 = group2.add_mutually_exclusive_group(required=required)
3687-
group3.add_argument('-e')
3688-
group3.add_argument('-f')
3689-
return parser
3690-
3691-
usage_when_not_required = '''\
3692-
usage: PROG [-h] [-a A | -b B | [-c C | -d D | [-e E | -f F]]]
3693-
'''
3694-
usage_when_required = '''\
3695-
usage: PROG [-h] (-a A | -b B | (-c C | -d D | (-e E | -f F)))
3696-
'''
3697-
3698-
help = '''\
3699-
3700-
options:
3701-
-h, --help show this help message and exit
3702-
-a A
3703-
-b B
3704-
-c C
3705-
-d D
3706-
-e E
3707-
-f F
3708-
'''
3709-
3710-
# We are only interested in testing the behavior of format_usage().
3711-
test_failures_when_not_required = None
3712-
test_failures_when_required = None
3713-
test_successes_when_not_required = None
3714-
test_successes_when_required = None
3715-
37163682

37173683
class TestMutuallyExclusiveOptionalOptional(MEMixin, TestCase):
37183684
def get_parser(self, required=None):
@@ -4883,25 +4849,6 @@ def test_all_suppressed_mutex_with_optional_nargs(self):
48834849
usage = 'usage: PROG [-h]\n'
48844850
self.assertEqual(parser.format_usage(), usage)
48854851

4886-
def test_nested_mutex_groups(self):
4887-
parser = argparse.ArgumentParser(prog='PROG')
4888-
g = parser.add_mutually_exclusive_group()
4889-
g.add_argument("--spam")
4890-
with warnings.catch_warnings():
4891-
warnings.simplefilter('ignore', DeprecationWarning)
4892-
gg = g.add_mutually_exclusive_group()
4893-
gg.add_argument("--hax")
4894-
gg.add_argument("--hox", help=argparse.SUPPRESS)
4895-
gg.add_argument("--hex")
4896-
g.add_argument("--eggs")
4897-
parser.add_argument("--num")
4898-
4899-
usage = textwrap.dedent('''\
4900-
usage: PROG [-h] [--spam SPAM | [--hax HAX | --hex HEX] | --eggs EGGS]
4901-
[--num NUM]
4902-
''')
4903-
self.assertEqual(parser.format_usage(), usage)
4904-
49054852
def test_long_mutex_groups_wrap(self):
49064853
parser = argparse.ArgumentParser(prog='PROG')
49074854
g = parser.add_mutually_exclusive_group()

Lib/test/test_complex.py

+5
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ def test_pow(self):
338338
except OverflowError:
339339
pass
340340

341+
# gh-113841: possible undefined division by 0 in _Py_c_pow()
342+
x, y = 9j, 33j**3
343+
with self.assertRaises(OverflowError):
344+
x**y
345+
341346
def test_pow_with_small_integer_exponents(self):
342347
# Check that small integer exponents are handled identically
343348
# regardless of their type.

0 commit comments

Comments
 (0)