Skip to content

Commit 4e29993

Browse files
committed
Merge remote-tracking branch 'upstream/main' into jump_if_bool
2 parents fcfd06c + f4b328e commit 4e29993

Some content is hidden

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

81 files changed

+729
-426
lines changed

Doc/c-api/memory.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ Customize Memory Allocators
403403
.. c:type:: PyMemAllocatorEx
404404
405405
Structure used to describe a memory block allocator. The structure has
406-
four fields:
406+
the following fields:
407407
408408
+----------------------------------------------------------+---------------------------------------+
409409
| Field | Meaning |

Doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139

140140
# Grouping the document tree into LaTeX files. List of tuples
141141
# (source start file, target name, title, author, document class [howto/manual]).
142-
_stdauthor = r'Guido van Rossum\\and the Python development team'
142+
_stdauthor = 'Guido van Rossum and the Python development team'
143143
latex_documents = [
144144
('c-api/index', 'c-api.tex',
145145
'The Python/C API', _stdauthor, 'manual'),

Doc/faq/programming.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,9 +1951,9 @@ relevant instance attributes are mutable, the *cached_property* approach
19511951
can't be made to work because it cannot detect changes to the
19521952
attributes.
19531953

1954-
The *lru_cache* approach can be made to work, but the class needs to define the
1955-
*__eq__* and *__hash__* methods so the cache can detect relevant attribute
1956-
updates::
1954+
To make the *lru_cache* approach work when the *station_id* is mutable,
1955+
the class needs to define the *__eq__* and *__hash__* methods so that
1956+
the cache can detect relevant attribute updates::
19571957

19581958
class Weather:
19591959
"Example with a mutable station identifier"

Doc/library/pickle.rst

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ to read the pickle produced.
147147
earlier versions of Python.
148148

149149
* Protocol version 2 was introduced in Python 2.3. It provides much more
150-
efficient pickling of :term:`new-style class`\es. Refer to :pep:`307` for
150+
efficient pickling of :term:`new-style classes <new-style class>`. Refer to :pep:`307` for
151151
information about improvements brought by protocol 2.
152152

153153
* Protocol version 3 was added in Python 3.0. It has explicit support for
@@ -261,7 +261,7 @@ process more convenient:
261261
protocol argument is needed. Bytes past the pickled representation
262262
of the object are ignored.
263263

264-
Arguments *file*, *fix_imports*, *encoding*, *errors*, *strict* and *buffers*
264+
Arguments *fix_imports*, *encoding*, *errors*, *strict* and *buffers*
265265
have the same meaning as in the :class:`Unpickler` constructor.
266266

267267
.. versionchanged:: 3.8
@@ -368,7 +368,7 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
368368

369369
.. versionadded:: 3.3
370370

371-
.. method:: reducer_override(self, obj)
371+
.. method:: reducer_override(obj)
372372

373373
Special reducer that can be defined in :class:`Pickler` subclasses. This
374374
method has priority over any reducer in the :attr:`dispatch_table`. It
@@ -494,20 +494,18 @@ What can be pickled and unpickled?
494494

495495
The following types can be pickled:
496496

497-
* ``None``, ``True``, and ``False``
498-
499-
* integers, floating point numbers, complex numbers
497+
* ``None``, ``True``, and ``False``;
500498

501-
* strings, bytes, bytearrays
499+
* integers, floating-point numbers, complex numbers;
502500

503-
* tuples, lists, sets, and dictionaries containing only picklable objects
501+
* strings, bytes, bytearrays;
504502

505-
* functions defined at the top level of a module (using :keyword:`def`, not
506-
:keyword:`lambda`)
503+
* tuples, lists, sets, and dictionaries containing only picklable objects;
507504

508-
* built-in functions defined at the top level of a module
505+
* functions (built-in and user-defined) defined at the top level of a module
506+
(using :keyword:`def`, not :keyword:`lambda`);
509507

510-
* classes that are defined at the top level of a module
508+
* classes defined at the top level of a module;
511509

512510
* instances of such classes whose the result of calling :meth:`__getstate__`
513511
is picklable (see section :ref:`pickle-inst` for details).
@@ -519,14 +517,14 @@ structure may exceed the maximum recursion depth, a :exc:`RecursionError` will b
519517
raised in this case. You can carefully raise this limit with
520518
:func:`sys.setrecursionlimit`.
521519

522-
Note that functions (built-in and user-defined) are pickled by "fully qualified"
523-
name reference, not by value. [#]_ This means that only the function name is
520+
Note that functions (built-in and user-defined) are pickled by fully qualified
521+
name, not by value. [#]_ This means that only the function name is
524522
pickled, along with the name of the module the function is defined in. Neither
525523
the function's code, nor any of its function attributes are pickled. Thus the
526524
defining module must be importable in the unpickling environment, and the module
527525
must contain the named object, otherwise an exception will be raised. [#]_
528526

529-
Similarly, classes are pickled by named reference, so the same restrictions in
527+
Similarly, classes are pickled by fully qualified name, so the same restrictions in
530528
the unpickling environment apply. Note that none of the class's code or data is
531529
pickled, so in the following example the class attribute ``attr`` is not
532530
restored in the unpickling environment::
@@ -536,7 +534,7 @@ restored in the unpickling environment::
536534

537535
picklestring = pickle.dumps(Foo)
538536

539-
These restrictions are why picklable functions and classes must be defined in
537+
These restrictions are why picklable functions and classes must be defined at
540538
the top level of a module.
541539

542540
Similarly, when class instances are pickled, their class's code and data are not
@@ -568,7 +566,7 @@ implementation of this behaviour::
568566
def save(obj):
569567
return (obj.__class__, obj.__dict__)
570568

571-
def load(cls, attributes):
569+
def restore(cls, attributes):
572570
obj = cls.__new__(cls)
573571
obj.__dict__.update(attributes)
574572
return obj
@@ -807,14 +805,15 @@ the code ::
807805
f = io.BytesIO()
808806
p = MyPickler(f)
809807

810-
does the same, but all instances of ``MyPickler`` will by default
811-
share the same dispatch table. The equivalent code using the
812-
:mod:`copyreg` module is ::
808+
does the same but all instances of ``MyPickler`` will by default
809+
share the private dispatch table. On the other hand, the code ::
813810

814811
copyreg.pickle(SomeClass, reduce_SomeClass)
815812
f = io.BytesIO()
816813
p = pickle.Pickler(f)
817814

815+
modifies the global dispatch table shared by all users of the :mod:`copyreg` module.
816+
818817
.. _pickle-state:
819818

820819
Handling Stateful Objects
@@ -1117,7 +1116,7 @@ Here is an example of an unpickler allowing only few safe classes from the
11171116
"""Helper function analogous to pickle.loads()."""
11181117
return RestrictedUnpickler(io.BytesIO(s)).load()
11191118

1120-
A sample usage of our unpickler working has intended::
1119+
A sample usage of our unpickler working as intended::
11211120

11221121
>>> restricted_loads(pickle.dumps([1, 2, range(15)]))
11231122
[1, 2, range(0, 15)]
@@ -1161,7 +1160,7 @@ For the simplest code, use the :func:`dump` and :func:`load` functions. ::
11611160

11621161
# An arbitrary collection of objects supported by pickle.
11631162
data = {
1164-
'a': [1, 2.0, 3, 4+6j],
1163+
'a': [1, 2.0, 3+4j],
11651164
'b': ("character string", b"byte string"),
11661165
'c': {None, True, False}
11671166
}
@@ -1217,6 +1216,6 @@ The following example reads the resulting pickled data. ::
12171216
operations.
12181217
12191218
.. [#] The limitation on alphanumeric characters is due to the fact
1220-
the persistent IDs, in protocol 0, are delimited by the newline
1219+
that persistent IDs in protocol 0 are delimited by the newline
12211220
character. Therefore if any kind of newline characters occurs in
1222-
persistent IDs, the resulting pickle will become unreadable.
1221+
persistent IDs, the resulting pickled data will become unreadable.

Doc/library/pkgutil.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ support.
2626
__path__ = extend_path(__path__, __name__)
2727

2828
This will add to the package's ``__path__`` all subdirectories of directories
29-
on ``sys.path`` named after the package. This is useful if one wants to
29+
on :data:`sys.path` named after the package. This is useful if one wants to
3030
distribute different parts of a single logical package as multiple
3131
directories.
3232

@@ -128,9 +128,9 @@ support.
128128

129129
Yield :term:`finder` objects for the given module name.
130130

131-
If fullname contains a '.', the finders will be for the package
131+
If fullname contains a ``'.'``, the finders will be for the package
132132
containing fullname, otherwise they will be all registered top level
133-
finders (i.e. those on both sys.meta_path and sys.path_hooks).
133+
finders (i.e. those on both :data:`sys.meta_path` and :data:`sys.path_hooks`).
134134

135135
If the named module is in a package, that package is imported as a side
136136
effect of invoking this function.
@@ -145,7 +145,7 @@ support.
145145
.. function:: iter_modules(path=None, prefix='')
146146

147147
Yields :class:`ModuleInfo` for all submodules on *path*, or, if
148-
*path* is ``None``, all top-level modules on ``sys.path``.
148+
*path* is ``None``, all top-level modules on :data:`sys.path`.
149149

150150
*path* should be either ``None`` or a list of paths to look for modules in.
151151

Doc/library/ssl.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ SSL sockets also have the following additional methods and attributes:
13971397
.. method:: SSLSocket.version()
13981398

13991399
Return the actual SSL protocol version negotiated by the connection
1400-
as a string, or ``None`` is no secure connection is established.
1400+
as a string, or ``None`` if no secure connection is established.
14011401
As of this writing, possible return values include ``"SSLv2"``,
14021402
``"SSLv3"``, ``"TLSv1"``, ``"TLSv1.1"`` and ``"TLSv1.2"``.
14031403
Recent OpenSSL versions may define more return values.
@@ -1548,7 +1548,7 @@ to speed up repeated connections from the same clients.
15481548
string must be the path to a single file in PEM format containing the
15491549
certificate as well as any number of CA certificates needed to establish
15501550
the certificate's authenticity. The *keyfile* string, if present, must
1551-
point to a file containing the private key in. Otherwise the private
1551+
point to a file containing the private key. Otherwise the private
15521552
key will be taken from *certfile* as well. See the discussion of
15531553
:ref:`ssl-certificates` for more information on how the certificate
15541554
is stored in the *certfile*.

Doc/library/stdtypes.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,11 @@ expression support in the :mod:`re` module).
21892189
>>> "they're bill's friends from the UK".title()
21902190
"They'Re Bill'S Friends From The Uk"
21912191

2192-
A workaround for apostrophes can be constructed using regular expressions::
2192+
The :func:`string.capwords` function does not have this problem, as it
2193+
splits words on spaces only.
2194+
2195+
Alternatively, a workaround for apostrophes can be constructed using regular
2196+
expressions::
21932197

21942198
>>> import re
21952199
>>> def titlecase(s):

Doc/whatsnew/3.11.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ Deprecated
833833
slated for removal in Python 3.13:
834834

835835
* :mod:`aifc`
836+
* :mod:`audioop`
836837

837838
(Contributed by Brett Cannon in :issue:`47061`.)
838839

@@ -1210,7 +1211,7 @@ Porting to Python 3.11
12101211
explicitly include the header files after ``#include <Python.h>``.
12111212
(Contributed by Victor Stinner in :issue:`45434`.)
12121213

1213-
* The non-limited API files ``cellobject.h``, ``classobject.h``, ``context.h``,
1214+
* The non-limited API files ``cellobject.h``, ``classobject.h``, ``code.h``, ``context.h``,
12141215
``funcobject.h``, ``genobject.h`` and ``longintrepr.h`` have been moved to
12151216
the ``Include/cpython`` directory. Moreover, the ``eval.h`` header file was
12161217
removed. These files must not be included directly, as they are already

Include/Python.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
#include "cpython/classobject.h"
6969
#include "fileobject.h"
7070
#include "pycapsule.h"
71-
#include "code.h"
71+
#include "cpython/code.h"
7272
#include "pyframe.h"
7373
#include "traceback.h"
7474
#include "sliceobject.h"

Include/code.h

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

Include/complexobject.h

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,22 @@
66
extern "C" {
77
#endif
88

9-
#ifndef Py_LIMITED_API
10-
typedef struct {
11-
double real;
12-
double imag;
13-
} Py_complex;
14-
15-
/* Operations on complex numbers from complexmodule.c */
16-
17-
PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex);
18-
PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex);
19-
PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex);
20-
PyAPI_FUNC(Py_complex) _Py_c_prod(Py_complex, Py_complex);
21-
PyAPI_FUNC(Py_complex) _Py_c_quot(Py_complex, Py_complex);
22-
PyAPI_FUNC(Py_complex) _Py_c_pow(Py_complex, Py_complex);
23-
PyAPI_FUNC(double) _Py_c_abs(Py_complex);
24-
#endif
25-
269
/* Complex object interface */
2710

28-
/*
29-
PyComplexObject represents a complex number with double-precision
30-
real and imaginary parts.
31-
*/
32-
#ifndef Py_LIMITED_API
33-
typedef struct {
34-
PyObject_HEAD
35-
Py_complex cval;
36-
} PyComplexObject;
37-
#endif
38-
3911
PyAPI_DATA(PyTypeObject) PyComplex_Type;
4012

4113
#define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)
4214
#define PyComplex_CheckExact(op) Py_IS_TYPE(op, &PyComplex_Type)
4315

44-
#ifndef Py_LIMITED_API
45-
PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
46-
#endif
4716
PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag);
4817

4918
PyAPI_FUNC(double) PyComplex_RealAsDouble(PyObject *op);
5019
PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op);
51-
#ifndef Py_LIMITED_API
52-
PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);
53-
#endif
5420

55-
/* Format the object based on the format_spec, as defined in PEP 3101
56-
(Advanced String Formatting). */
5721
#ifndef Py_LIMITED_API
58-
PyAPI_FUNC(int) _PyComplex_FormatAdvancedWriter(
59-
_PyUnicodeWriter *writer,
60-
PyObject *obj,
61-
PyObject *format_spec,
62-
Py_ssize_t start,
63-
Py_ssize_t end);
22+
# define Py_CPYTHON_COMPLEXOBJECT_H
23+
# include "cpython/complexobject.h"
24+
# undef Py_CPYTHON_COMPLEXOBJECT_H
6425
#endif
6526

6627
#ifdef __cplusplus

Include/cpython/code.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
#ifndef Py_CPYTHON_CODE_H
2-
# error "this header file must not be included directly"
1+
/* Definitions for bytecode */
2+
3+
#ifndef Py_LIMITED_API
4+
#ifndef Py_CODE_H
5+
#define Py_CODE_H
6+
#ifdef __cplusplus
7+
extern "C" {
38
#endif
49

510
/* Each instruction in a code object is a fixed-width value,
@@ -204,3 +209,9 @@ PyAPI_FUNC(int) _PyCode_GetExtra(PyObject *code, Py_ssize_t index,
204209
void **extra);
205210
PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
206211
void *extra);
212+
213+
#ifdef __cplusplus
214+
}
215+
#endif
216+
#endif // !Py_CODE_H
217+
#endif // !Py_LIMITED_API

0 commit comments

Comments
 (0)