8000 Merge branch 'main' into gh-117376-deferred-rc · python/cpython@1d2d548 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d2d548

Browse files
committed
Merge branch 'main' into gh-117376-deferred-rc
2 parents f8add0e + c50cb6d commit 1d2d548

Some content is hidden

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

61 files changed

+2129
-740
lines changed

Doc/library/decimal.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ are also included in the pure Python version for compatibility.
15171517
the C version uses a thread-local rather than a coroutine-local context and the value
15181518
is ``False``. This is slightly faster in some nested context scenarios.
15191519

1520-
.. versionadded:: 3.8.3
1520+
.. versionadded:: 3.8.3
15211521

15221522

15231523
Rounding modes

Doc/library/ipaddress.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,14 @@ write code that handles both IP versions correctly. Address objects are
334334
.. attribute:: is_multicast
335335
.. attribute:: is_private
336336
.. attribute:: is_global
337+
338+
.. versionadded:: 3.4
339+
337340
.. attribute:: is_unspecified
338341
.. attribute:: is_reserved
339342
.. attribute:: is_loopback
340343
.. attribute:: is_link_local
341344

342-
.. versionadded:: 3.4
343-
is_global
344-
345345
.. attribute:: is_site_local
346346

347347
``True`` if the address is reserved for site-local usage. Note that

Doc/library/ssl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ to speed up repeated connections from the same clients.
18201820
.. versionchanged:: 3.6
18211821
*session* argument was added.
18221822

1823-
.. versionchanged:: 3.7
1823+
.. versionchanged:: 3.7
18241824
The method returns an instance of :attr:`SSLContext.sslsocket_class`
18251825
instead of hard-coded :class:`SSLSocket`.
18261826

Doc/library/urllib.request.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ The :mod:`urllib.request` module defines the following functions:
113113
``http/1.1`` when no *context* is given. Custom *context* should set
114114
ALPN protocols with :meth:`~ssl.SSLContext.set_alpn_protocols`.
115115

116-
.. versionchanged:: 3.13
117-
Remove *cafile*, *capath* and *cadefault* parameters: use the *context*
118-
parameter instead.
116+
.. versionchanged:: 3.13
117+
Remove *cafile*, *capath* and *cadefault* parameters: use the *context*
118+
parameter instead.
119119

120120

121121
.. function:: install_opener(opener)

Include/internal/pycore_bytes_methods.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ extern void _Py_bytes_title(char *result, const char *s, Py_ssize_t len);
2626
extern void _Py_bytes_capitalize(char *result, const char *s, Py_ssize_t len);
2727
extern void _Py_bytes_swapcase(char *result, const char *s, Py_ssize_t len);
2828

29-
extern PyObject *_Py_bytes_find(const char *str, Py_ssize_t len, PyObject *args);
30-
extern PyObject *_Py_bytes_index(const char *str, Py_ssize_t len, PyObject *args);
31-
extern PyObject *_Py_bytes_rfind(const char *str, Py_ssize_t len, PyObject *args);
32-
extern PyObject *_Py_bytes_rindex(const char *str, Py_ssize_t len, PyObject *args);
33-
extern PyObject *_Py_bytes_count(const char *str, Py_ssize_t len, PyObject *args);
29+
extern PyObject *_Py_bytes_find(const char *str, Py_ssize_t len, PyObject *sub,
30+
Py_ssize_t start, Py_ssize_t end);
31+
extern PyObject *_Py_bytes_index(const char *str, Py_ssize_t len, PyObject *sub,
32+
Py_ssize_t start, Py_ssize_t end);
33+
extern PyObject *_Py_bytes_rfind(const char *str, Py_ssize_t len, PyObject *sub,
34+
Py_ssize_t start, Py_ssize_t end);
35+
extern PyObject *_Py_bytes_rindex(const char *str, Py_ssize_t len, PyObject *sub,
36+
Py_ssize_t start, Py_ssize_t end);
37+
extern PyObject *_Py_bytes_count(const char *str, Py_ssize_t len, PyObject *sub,
38+
Py_ssize_t start, Py_ssize_t end);
3439
extern int _Py_bytes_contains(const char *str, Py_ssize_t len, PyObject *arg);
3540
extern PyObject *_Py_bytes_startswith(const char *str, Py_ssize_t len,
3641
PyObject *subobj, Py_ssize_t start,

Include/internal/pycore_crossinterp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ PyAPI_FUNC(int) _PyXI_HasCapturedException(_PyXI_session *session);
325325
// Export for _testinternalcapi shared extension
326326
PyAPI_FUNC(PyInterpreterState *) _PyXI_NewInterpreter(
327327
PyInterpreterConfig *config,
328+
long *maybe_whence,
328329
PyThreadState **p_tstate,
329330
PyThreadState **p_save_tstate);
330331
PyAPI_FUNC(void) _PyXI_EndInterpreter(

Include/internal/pycore_global_objects_fini_generated.h

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

Include/internal/pycore_global_strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ struct _Py_global_strings {
764764
STRUCT_FOR_ID(version)
765765
STRUCT_FOR_ID(volume)
766766
STRUCT_FOR_ID(wait_all)
767+
STRUCT_FOR_ID(warn_on_full_buffer)
767768
STRUCT_FOR_ID(warnings)
768769
STRUCT_FOR_ID(warnoptions)
769770
STRUCT_FOR_ID(wbits)

Include/internal/pycore_interp.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ struct _is {
109109
#define _PyInterpreterState_WHENCE_LEGACY_CAPI 2
110110
#define _PyInterpreterState_WHENCE_CAPI 3
111111
#define _PyInterpreterState_WHENCE_XI 4
112-
#define _PyInterpreterState_WHENCE_MAX 4
112+
#define _PyInterpreterState_WHENCE_STDLIB 5
113+
#define _PyInterpreterState_WHENCE_MAX 5
113114
long _whence;
114115

115116
/* Has been initialized to a safe state.
@@ -316,6 +317,8 @@ PyAPI_FUNC(int) _PyInterpreterState_IDInitref(PyInterpreterState *);
316317
PyAPI_FUNC(int) _PyInterpreterState_IDIncref(PyInterpreterState *);
317318
PyAPI_FUNC(void) _PyInterpreterState_IDDecref(PyInterpreterState *);
318319

320+
PyAPI_FUNC(int) _PyInterpreterState_IsReady(PyInterpreterState *interp);
321+
319322
PyAPI_FUNC(long) _PyInterpreterState_GetWhence(PyInterpreterState *interp);
320323
extern void _PyInterpreterState_SetWhence(
321324
PyInterpreterState *interp,

Include/internal/pycore_runtime_init_generated.h

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

Include/internal/pycore_typeobject.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ PyAPI_FUNC(PyObject*) _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj,
152152

153153
extern PyObject* _PyType_GetFullyQualifiedName(PyTypeObject *type, char sep);
154154

155+
// Perform the following operation, in a thread-safe way when required by the
156+
// build mode.
157+
//
158+
// self->tp_flags = (self->tp_flags & ~mask) | flags;
159+
extern void _PyType_SetFlags(PyTypeObject *self, unsigned long mask,
160+
unsigned long flags);
161+
162+
// Like _PyType_SetFlags(), but apply the operation to self and any of its
163+
// subclasses without Py_TPFLAGS_IMMUTABLETYPE set.
164+
extern void _PyType_SetFlagsRecursive(PyTypeObject *self, unsigned long mask,
165+
unsigned long flags);
166+
155167

156168
#ifdef __cplusplus
157169
}

Include/internal/pycore_unicodeobject_generated.h

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

Lib/test/support/interpreters/__init__.py

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,51 +74,77 @@ def __str__(self):
7474
def create():
7575
"""Return a new (idle) Python interpreter."""
7676
id = _interpreters.create(reqrefs=True)
77-
return Interpreter(id)
77+
return Interpreter(id, _ownsref=True)
7878

7979

8080
def list_all():
8181
"""Return all existing interpreters."""
82-
return [Interpreter(id)
83-
for id, in _interpreters.list_all()]
82+
return [Interpreter(id, _whence=whence)
83+
for id, whence in _interpreters.list_all(require_ready=True)]
8484

8585

8686
def get_current():
8787
"""Return the currently running interpreter."""
88-
id, = _interpreters.get_current()
89-
return Interpreter(id)
88+
id, whence = _interpreters.get_current()
89+
return Interpreter(id, _whence=whence)
9090

9191

9292
def get_main():
9393
"""Return the main interpreter."""
94-
id, = _interpreters.get_main()
95-
return Interpreter(id)
94+
id, whence = _interpreters.get_main()
95+
assert whence == _interpreters.WHENCE_RUNTIME, repr(whence)
96+
return Interpreter(id, _whence=whence)
9697

9798

9899
_known = weakref.WeakValueDictionary()
99100

100101
class Interpreter:
101-
"""A single Python interpreter."""
102+
"""A single Python interpreter.
102103
103-
def __new__(cls, id, /):
104+
Attributes:
105+
106+
"id" - the unique process-global ID number for the interpreter
107+
"whence" - indicates where the interpreter was created
108+
109+
If the interpreter wasn't created by this module
110+
then any method that modifies the interpreter will fail,
111+
i.e. .close(), .prepare_main(), .exec(), and .call()
112+
"""
113+
114+
_WHENCE_TO_STR = {
115+
_interpreters.WHENCE_UNKNOWN: 'unknown',
116+
_interpreters.WHENCE_RUNTIME: 'runtime init',
117+
_interpreters.WHENCE_LEGACY_CAPI: 'legacy C-API',
118+
_interpreters.WHENCE_CAPI: 'C-API',
119+
_interpreters.WHENCE_XI: 'cross-interpreter C-API',
120+
_interpreters.WHENCE_STDLIB: '_interpreters module',
121+
}
122+
123+
def __new__(cls, id, /, _whence=None, _ownsref=None):
104124
# There is only one instance for any given ID.
105125
if not isinstance(id, int):
106126
raise TypeError(f'id must be an int, got {id!r}')
107127
id = int(id)
128+
if _whence is None:
129+
if _ownsref:
130+
_whence = _interpreters.WHENCE_STDLIB
131+
else:
132+
_whence = _interpreters.whence(id)
133+
assert _whence in cls._WHENCE_TO_STR, repr(_whence)
134+
if _ownsref is None:
135+
_ownsref = (_whence == _interpreters.WHENCE_STDLIB)
108136
try:
109137
self = _known[id]
110138
assert hasattr(self, '_ownsref')
111139
except KeyError:
112-
# This may raise InterpreterNotFoundError:
113-
_interpreters.incref(id)
114-
try:
115-
self = super().__new__(cls)
116-
self._id = id
117-
self._ownsref = True
118-
except BaseException:
119-
_interpreters.decref(id)
120-
raise
140+
self = super().__new__(cls)
121141
_known[id] = self
142+
self._id = id
143+
self._whence = _whence
144+
self._ownsref = _ownsref
145+
if _ownsref:
146+
# This may raise InterpreterNotFoundError:
147+
_interpreters.incref(id)
122148
return self
123149

124150
def __repr__(self):
@@ -143,33 +169,40 @@ def _decref(self):
143169
return
144170
self._ownsref = False
145171
try:
146-
_interpreters.decref(self.id)
172+
_interpreters.decref(self._id)
147173
except InterpreterNotFoundError:
148174
pass
149175

150176
@property
151177
def id(self):
152178
return self._id
153179

180+
@property
181+
def whence(self):
182+
return self._WHENCE_TO_STR[self._whence]
183+
154184
def is_running(self):
155185
"""Return whether or not the identified interpreter is running."""
156186
return _interpreters.is_running(self._id)
157187

188+
# Everything past here is available only to interpreters created by
189+
# interpreters.create().
190+
158191
def close(self):
159192
"""Finalize and destroy the interpreter.
160193
161194
Attempting to destroy the current interpreter results
162195
in an InterpreterError.
163196
"""
164-
return _interpreters.destroy(self._id)
197+
return _interpreters.destroy(self._id, restrict=True)
165198

166199
def prepare_main(self, ns=None, /, **kwargs):
167200
"""Bind the given values into the interpreter's __main__.
168201
169202
The values must be shareable.
170203
"""
171204
ns = dict(ns, **kwargs) if ns is not None else kwargs
172-
_interpreters.set___main___attrs(self._id, ns)
205+
_interpreters.set___main___attrs(self._id, ns, restrict=True)
173206

174207
def exec(self, code, /):
175208
"""Run the given source code in the interpreter.
@@ -189,7 +222,7 @@ def exec(self, code, /):
189222
that time, the previous interpreter is allowed to run
190223
in other threads.
191224
"""
192-
excinfo = _interpreters.exec(self._id, code)
225+
excinfo = _interpreters.exec(self._id, code, restrict=True)
193226
if excinfo is not None:
194227
raise ExecutionFailed(excinfo)
195228

@@ -209,7 +242,7 @@ def call(self, callable, /):
209242
# XXX Support args and kwargs.
210243
# XXX Support arbitrary callables.
211244
# XXX Support returning the return value (e.g. via pickle).
212-
excinfo = _interpreters.call(self._id, callable)
245+
excinfo = _interpreters.call(self._id, callable, restrict=True)
213246
if excinfo is not None:
214247
raise ExecutionFailed(excinfo)
215248

Lib/test/test_capi/test_misc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,6 +2139,9 @@ def check(enabled, override):
21392139
}
21402140

21412141
r, w = os.pipe()
2142+
if Py_GIL_DISABLED:
2143+
# gh-117649: The test fails before `w` is closed
2144+
self.addCleanup(os.close, w)
21422145
script = textwrap.dedent(f'''
21432146
from test.test_capi.check_config import run_singlephase_check
21442147
run_singlephase_check({override}, {w})

Lib/test/test_descr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,10 +1687,10 @@ class D(C):
16871687
self.assertEqual(d.foo(1), (d, 1))
16881688
self.assertEqual(D.foo(d, 1), (d, 1))
16891689
sm = staticmethod(None)
1690-
self.assertEqual(sm.__dict__, {'__doc__': None})
1690+
self.assertEqual(sm.__dict__, {'__doc__': None.__doc__})
16911691
sm.x = 42
16921692
self.assertEqual(sm.x, 42)
1693-
self.assertEqual(sm.__dict__, {"x" : 42, '__doc__': None})
1693+
self.assertEqual(sm.__dict__, {"x" : 42, '__doc__': None.__doc__})
16941694
del sm.x
16951695
self.assertNotHasAttr(sm, "x")
16961696

0 commit comments

Comments
 (0)
0