8000 Merge branch 'main' into module-setdelattr · python/cpython@280fc0e · GitHub
[go: up one dir, main page]

Skip to content

Commit 280fc0e

Browse files
authored
Merge branch 'main' into module-setdelattr
2 parents 49c82c5 + aa9a359 commit 280fc0e

File tree

97 files changed

+911
-565
lines changed

Some content is hidden

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

97 files changed

+911
-565
lines changed

Doc/c-api/typeobj.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
14031403
are allowed to be removed even if the instance is still alive).
14041404

14051405
Note that :c:func:`Py_VISIT` requires the *visit* and *arg* parameters to
1406-
:c:func:`local_traverse` to have these specific names; don't name them just
1406+
:c:func:`!local_traverse` to have these specific names; don't name them just
14071407
anything.
14081408

14091409
Instances of :ref:`heap-allocated types <heap-types>` hold a reference to

Doc/library/dataclasses.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ methods will raise a :exc:`FrozenInstanceError` when invoked.
609609

610610
There is a tiny performance penalty when using ``frozen=True``:
611611
:meth:`~object.__init__` cannot use simple assignment to initialize fields, and
612-
must use :meth:`~object.__setattr__`.
612+
must use :meth:`!object.__setattr__`.
613613

614614
Inheritance
615615
-----------

Doc/library/time.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ Functions
379379
* Or use ``nanosleep()`` if available (resolution: 1 nanosecond);
380380
* Or use ``select()`` (resolution: 1 microsecond).
381381

382+
.. audit-event:: time.sleep secs
383+
382384
.. versionchanged:: 3.11
383385
On Unix, the ``clock_nanosleep()`` and ``nanosleep()`` functions are now
384386
used if available. On Windows, a waitable timer is now used.
@@ -389,6 +391,9 @@ Functions
389391
:pep:`475` for the rationale).
390392

391393

394+
.. versionchanged:: 3.13
395+
Raises an auditing event.
396+
392397
.. index::
393398
single: % (percent); datetime format
394399

Doc/whatsnew/2.6.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ about features that will be removed in Python 3.0. You can run code
121121
with this switch to see how much work will be necessary to port
122122
code to 3.0. The value of this switch is available
123123
to Python code as the boolean variable :data:`sys.py3kwarning`,
124-
and to C extension code as :c:data:`Py_Py3kWarningFlag`.
124+
and to C extension code as :c:data:`!Py_Py3kWarningFlag`.
125125

126126
.. seealso::
127127

Doc/whatsnew/2.7.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,22 +2155,22 @@ Changes to Python's build process and to the C API include:
21552155
:c:func:`!PyOS_ascii_strtod` and :c:func:`!PyOS_ascii_atof` functions
21562156
are now deprecated.
21572157

2158-
* New function: :c:func:`PySys_SetArgvEx` sets the value of
2158+
* New function: :c:func:`!PySys_SetArgvEx` sets the value of
21592159
``sys.argv`` and can optionally update ``sys.path`` to include the
21602160
directory containing the script named by ``sys.argv[0]`` depending
21612161
on the value of an *updatepath* parameter.
21622162

21632163
This function was added to close a security hole for applications
2164-
that embed Python. The old function, :c:func:`PySys_SetArgv`, would
2164+
that embed Python. The old function, :c:func:`!PySys_SetArgv`, would
21652165
always update ``sys.path``, and sometimes it would add the current
21662166
directory. This meant that, if you ran an application embedding
21672167
Python in a directory controlled by someone else, attackers could
21682168
put a Trojan-horse module in the directory (say, a file named
21692169
:file:`os.py`) that your application would then import and run.
21702170

21712171
If you maintain a C/C++ application that embeds Python, check
2172-
whether you're calling :c:func:`PySys_SetArgv` and carefully consider
2173-
whether the application should be using :c:func:`PySys_SetArgvEx`
2172+
whether you're calling :c:func:`!PySys_SetArgv` and carefully consider
2173+
whether the application should be using :c:func:`!PySys_SetArgvEx`
21742174
with *updatepath* set to false.
21752175

21762176
Security issue reported as `CVE-2008-5983
@@ -2545,11 +2545,11 @@ For C extensions:
25452545

25462546
For applications that embed Python:
25472547

2548-
* The :c:func:`PySys_SetArgvEx` function was added, letting
2548+
* The :c:func:`!PySys_SetArgvEx` function was added, letting
25492549
applications close a security hole when the existing
2550-
:c:func:`PySys_SetArgv` function was used. Check whether you're
2551-
calling :c:func:`PySys_SetArgv` and carefully consider whether the
2552-
application should be using :c:func:`PySys_SetArgvEx` with
2550+
:c:func:`!PySys_SetArgv` function was used. Check whether you're
2551+
calling :c:func:`!PySys_SetArgv` and carefully consider whether the
2552+
application should be using :c:func:`!PySys_SetArgvEx` with
25532553
*updatepath* set to false.
25542554

25552555
.. ======================================================================

Doc/whatsnew/3.11.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ Other Language Changes
459459
:class:`collections.OrderedDict`, :class:`collections.deque`,
460460
:class:`weakref.WeakSet`, and :class:`datetime.tzinfo` now copies and
461461
pickles instance attributes implemented as :term:`slots <__slots__>`.
462+
This change has an unintended side effect: It trips up a small minority
463+
of existing Python projects not expecting :meth:`object.__getstate__` to
464+
exist. See the later comments on :gh:`70766` for discussions of what
465+
workarounds such code may need.
462466
(Contributed by Serhiy Storchaka in :issue:`26579`.)
463467

464468
.. _whatsnew311-pythonsafepath:

Doc/whatsnew/3.4.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ Other Build and C API Changes
18911891
allowing retrieval of function pointers from named type slots when using
18921892
the limited API. (Contributed by Martin von Löwis in :issue:`17162`.)
18931893

1894-
* The new :c:func:`Py_SetStandardStreamEncoding` pre-initialization API
1894+
* The new :c:func:`!Py_SetStandardStreamEncoding` pre-initialization API
18951895
allows applications embedding the CPython interpreter to reliably force
18961896
a particular encoding and error handler for the standard streams.
18971897
(Contributed by Bastien Montagne and Nick Coghlan in :issue:`16129`.)

Doc/whatsnew/3.7.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,12 +2495,12 @@ either in embedding applications, or in CPython itself.
24952495
:issue:`22257`, and further updated by Nick, Eric, and Victor Stinner in a
24962496
number of other issues). Some known details affected:
24972497

2498-
* :c:func:`PySys_AddWarnOptionUnicode` is not currently usable by embedding
2498+
* :c:func:`!PySys_AddWarnOptionUnicode` is not currently usable by embedding
24992499
applications due to the requirement to create a Unicode object prior to
2500-
calling ``Py_Initialize``. Use :c:func:`PySys_AddWarnOption` instead.
2500+
calling ``Py_Initialize``. Use :c:func:`!PySys_AddWarnOption` instead.
25012501

25022502
* warnings filters added by an embedding application with
2503-
:c:func:`PySys_AddWarnOption` should now more consistently take precedence
2503+
:c:func:`!PySys_AddWarnOption` should now more consistently take precedence
25042504
over the default filters set by the interpreter
25052505

25062506
Due to changes in the way the default warnings filters are configured,

Include/internal/pycore_compile.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ PyAPI_FUNC(PyCodeObject*) _PyAST_Compile(
1919 int optimize,
2020
struct _arena *arena);
2121

22+
/* AST optimizations */
23+
PyAPI_FUNC(int) _PyCompile_AstOptimize(
24+
struct _mod *mod,
25+
PyObject *filename,
26+
PyCompilerFlags *flags,
27+
int optimize,
28+
struct _arena *arena);
29+
2230
static const _PyCompilerSrcLocation NO_LOCATION = {-1, -1, -1, -1};
2331

2432
extern int _PyAST_Optimize(

Include/internal/pycore_opcode.h

Lines changed: 0 additions & 40 deletions
This file was deleted.

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_opcode_utils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
#include "pycore_opcode.h" // JUMP_FORWARD
12-
11+
#include "opcode_ids.h"
1312

1413
#define MAX_REAL_OPCODE 254
1514

Include/pycapsule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ PyAPI_FUNC(int) PyCapsule_SetName(PyObject *capsule, const char *name);
4848

4949
PyAPI_FUNC(int) PyCapsule_SetContext(PyObject *capsule, void *context);
5050

51+
#ifdef Py_BUILD_CORE
52+
PyAPI_FUNC(int) _PyCapsule_SetTraverse(PyObject *op, traverseproc traverse_func, inquiry clear_func);
53+
#endif
54+
5155
PyAPI_FUNC(void *) PyCapsule_Import(
5256
const char *name, /* UTF-8 encoded string */
5357
int no_block);

Lib/multiprocessing/synchronize.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class SemLock(object):
5050
def __init__(self, kind, value, maxvalue, *, ctx):
5151
if ctx is None:
5252
ctx = context._default_context.get_context()
53-
name = ctx.get_start_method()
54-
unlink_now = sys.platform == 'win32' or name == 'fork'
53+
self.is_fork_ctx = ctx.get_start_method() == 'fork'
54+
unlink_now = sys.platform == 'win32' or self.is_fork_ctx
5555
for i in range(100):
5656
try:
5757
sl = self._semlock = _multiprocessing.SemLock(
@@ -103,6 +103,11 @@ def __getstate__(self):
103103
if sys.platform == 'win32':
104104
h = context.get_spawning_popen().duplicate_for_child(sl.handle)
105105
else:
106+
if self.is_fork_ctx:
107+
raise RuntimeError('A SemLock created in a fork context is being '
108+
'shared with a process in a spawn context. This is '
109+
'not supported. Please use the same context to create '
110+
'multiprocessing objects and Process.')
106111
h = sl.handle
107112
return (h, sl.kind, sl.maxvalue, sl.name)
108113

Lib/opcode.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,40 @@
55
"""
66

77

8-
# Note that __all__ is further extended below
9-
__all__ = ["cmp_op", "stack_effect", "hascompare"]
8+
__all__ = ["cmp_op", "stack_effect", "hascompare", "opname", "opmap",
9+
"HAVE_ARGUMENT", "EXTENDED_ARG", "hasarg", "hasconst", "hasname",
10+
"hasjump", "hasjrel", "hasjabs", "hasfree", "haslocal", "hasexc"]
1011

1112
import _opcode
1213
from _opcode import stack_effect
1314

14-
import sys
15-
# The build uses older versions of Python which do not have _opcode_metadata
16-
if sys.version_info[:2] >= (3, 13):
17-
from _opcode_metadata import _specializations, _specialized_opmap
18-
from _opcode_metadata import opmap, HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE
19-
EXTENDED_ARG = opmap['EXTENDED_ARG']
15+
from _opcode_metadata import (_specializations, _specialized_opmap, opmap,
16+
HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE)
17+
EXTENDED_ARG = opmap['EXTENDED_ARG']
2018

21-
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
22-
for op, i in opmap.items():
23-
opname[i] = op
24-
25-
__all__.extend(["opname", "opmap", "HAVE_ARGUMENT", "EXTENDED_ARG"])
19+
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
20+
for op, i in opmap.items():
21+
opname[i] = op
2622

2723
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
2824

29-
# The build uses older versions of Python which do not have _opcode.has_* functions
30-
if sys.version_info[:2] >= (3, 13):
31-
# These lists are documented as part of the dis module's API
32-
hasarg = [op for op in opmap.values() if _opcode.has_arg(op)]
33-
hasconst = [op for op in opmap.values() if _opcode.has_const(op)]
34-
hasname = [op for op in opmap.values() if _opcode.has_name(op)]
35-
hasjump = [op for op in opmap.values() if _opcode.has_jump(op)]
36-
hasjrel = hasjump # for backward compatibility
37-
hasjabs = []
38-
hasfree = [op for op in opmap.values() if _opcode.has_free(op)]
39-
haslocal = [op for op in opmap.values() if _opcode.has_local(op)]
40-
hasexc = [op for op in opmap.values() if _opcode.has_exc(op)]
25+
# These lists are documented as part of the dis module's API
26+
hasarg = [op for op in opmap.values() if _opcode.has_arg(op)]
27+
hasconst = [op for op in opmap.values() if _opcode.has_const(op)]
28+
hasname = [op for op in opmap.values() if _opcode.has_name(op)]
29+
hasjump = [op for op in opmap.values() if _opcode.has_jump(op)]
30+
hasjrel = hasjump # for backward compatibility
31+
hasjabs = []
32+
hasfree = [op for op in opmap.values() if _opcode.has_free(op)]
33+
haslocal = [op for op in opmap.values() if _opcode.has_local(op)]
34+
hasexc = [op for op in opmap.values() if _opcode.has_exc(op)]
4135

42-
__all__.extend(["hasarg", "hasconst", "hasname", "hasjump", "hasjrel",
43-
"hasjabs", "hasfree", "haslocal", "hasexc"])
4436

45-
_intrinsic_1_descs = _opcode.get_intrinsic1_descs()
46-
_intrinsic_2_descs = _opcode.get_intrinsic2_descs()
47-
_nb_ops = _opcode.get_nb_ops()
37+
_intrinsic_1_descs = _opcode.get_intrinsic1_descs()
38+
_intrinsic_2_descs = _opcode.get_intrinsic2_descs()
39+
_nb_ops = _opcode.get_nb_ops()
4840

49-
hascompare = [opmap["COMPARE_OP"]]
41+
hascompare = [opmap["COMPARE_OP"]]
5042

5143
_cache_format = {
5244
"LOAD_GLOBAL": {

Lib/tarfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2557,7 +2557,8 @@ def chown(self, tarinfo, targetpath, numeric_owner):
25572557
os.lchown(targetpath, u, g)
25582558
else:
25592559
os.chown(targetpath, u, g)
2560-
except OSError as e:
2560+
except (OSError, OverflowError) as e:
2561+
# OverflowError can be raised if an ID doesn't fit in `id_t`
25612562
raise ExtractError("could not change owner") from e
25622563

25632564
def chmod(self, tarinfo, targetpath):

Lib/test/_test_multiprocessing.py

Expand all lines: Lib/test/_test_multiprocessing.py
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5421,6 +5421,28 @@ def test_preload_resources(self):
54215421
print(err)
54225422
self.fail("failed spawning forkserver or grandchild")
54235423

5424+
@unittest.skipIf(sys.platform == "win32",
5425+
"Only Spawn on windows so no risk of mixing")
5426+
@only_run_in_spawn_testsuite("avoids redundant testing.")
5427+
def test_mixed_startmethod(self):
5428+
# Fork-based locks cannot be used with spawned process
5429+
for process_method in ["spawn", "forkserver"]:
5430+
queue = multiprocessing.get_context("fork").Queue()
5431+
process_ctx = multiprocessing.get_context(process_method)
5432+
p = process_ctx.Process(target=close_queue, args=(queue,))
5433+
err_msg = "A SemLock created in a fork"
5434+
with self.assertRaisesRegex(RuntimeError, err_msg):
5435+
p.start()
5436+
5437+
# non-fork-based locks can be used with all other start methods
5438+
for queue_method in ["spawn", "forkserver"]:
5439+
for process_method in multiprocessing.get_all_start_methods():
5440+
queue = multiprocessing.get_context(queue_method).Queue()
5441+
process_ctx = multiprocessing.get_context(process_method)
5442+
p = process_ctx.Process(target=close_queue, args=(queue,))
5443+
p.start()
5444+
p.join()
5445+
54245446

54255447
@unittest.skipIf(sys.platform == "win32",
54265448
"test semantics don't make sense on Windows")
@@ -6104,7 +6126,8 @@ class ThreadsMixin(BaseMixin):
61046126
# Functions used to create test cases from the base ones in this module
61056127
#
61066128

6107-
def install_tests_in_module_dict(remote_globs, start_method):
6129+
def install_tests_in_module_dict(remote_globs, start_method,
6130+
only_type=None, exclude_types=False):
61086131
__module__ = remote_globs['__name__']
61096132
local_globs = globals()
61106133
ALL_TYPES = {'processes', 'threads', 'manager'}
@@ -6117,6 +6140,10 @@ def install_tests_in_module_dict(remote_globs, start_method):
61176140
continue
61186141
assert set(base.ALLOWED_TYPES) <= ALL_TYPES, base.ALLOWED_TYPES
61196142
for type_ in base.ALLOWED_TYPES:
6143+
if only_type and type_ != only_type:
6144+
continue
6145+
if exclude_types:
6146+
continue
61206147
newname = 'With' + type_.capitalize() + name[1:]
61216148
Mixin = local_globs[type_.capitalize() + 'Mixin']
61226149
class Temp(base, Mixin, unittest.TestCase):
@@ -6127,6 +6154,9 @@ class Temp(base, Mixin, unittest.TestCase):
61276154
Temp.__module__ = __module__
61286155
remote_globs[newname] = Temp
61296156
elif issubclass(base, unittest.TestCase):
6157+
if only_type:
6158+
continue
6159+
61306160
class Temp(base, object):
61316161
pass
61326162
Temp.__name__ = Temp.__qualname__ = name

0 commit comments

Comments
 (0)
0