Skip to content

Commit 1266cb5

Browse files
authored
Merge pull request #506 from python/main
Sync Fork from Upstream Repo
2 parents 63b74de + 22e7eff commit 1266cb5

130 files changed

Lines changed: 7149 additions & 6360 deletions

File tree

Some content is hidden

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

Doc/c-api/import.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,8 @@ Importing Modules
299299
field; failure to provide the sentinel value can result in a memory fault.
300300
Returns ``0`` on success or ``-1`` if insufficient memory could be allocated to
301301
extend the internal table. In the event of failure, no modules are added to the
302-
internal table. This should be called before :c:func:`Py_Initialize`.
302+
internal table. This must be called before :c:func:`Py_Initialize`.
303+
304+
If Python is initialized multiple times, :c:func:`PyImport_AppendInittab` or
305+
:c:func:`PyImport_ExtendInittab` must be called before each Python
306+
initialization.

Doc/c-api/init_config.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,10 @@ The caller is responsible to handle exceptions (error or exit) using
11931193
11941194
If :c:func:`PyImport_FrozenModules`, :c:func:`PyImport_AppendInittab` or
11951195
:c:func:`PyImport_ExtendInittab` are used, they must be set or called after
1196-
Python preinitialization and before the Python initialization.
1196+
Python preinitialization and before the Python initialization. If Python is
1197+
initialized multiple times, :c:func:`PyImport_AppendInittab` or
1198+
:c:func:`PyImport_ExtendInittab` must be called before each Python
1199+
initialization.
11971200
11981201
The current configuration (``PyConfig`` type) is stored in
11991202
``PyInterpreterState.config``.

Doc/c-api/veryhigh.rst

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -185,42 +185,6 @@ the same library that the Python runtime is using.
185185
:c:func:`PyMem_RawRealloc`, instead of being allocated by
186186
:c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`.
187187
188-
189-
.. c:function:: struct _node* PyParser_SimpleParseString(const char *str, int start)
190-
191-
This is a simplified interface to
192-
:c:func:`PyParser_SimpleParseStringFlagsFilename` below, leaving *filename* set
193-
to ``NULL`` and *flags* set to ``0``.
194-
195-
196-
.. c:function:: struct _node* PyParser_SimpleParseStringFlags( const char *str, int start, int flags)
197-
198-
This is a simplified interface to
199-
:c:func:`PyParser_SimpleParseStringFlagsFilename` below, leaving *filename* set
200-
to ``NULL``.
201-
202-
203-
.. c:function:: struct _node* PyParser_SimpleParseStringFlagsFilename( const char *str, const char *filename, int start, int flags)
204-
205-
Parse Python source code from *str* using the start token *start* according to
206-
the *flags* argument. The result can be used to create a code object which can
207-
be evaluated efficiently. This is useful if a code fragment must be evaluated
208-
many times. *filename* is decoded from the :term:`filesystem encoding and
209-
error handler`.
210-
211-
212-
.. c:function:: struct _node* PyParser_SimpleParseFile(FILE *fp, const char *filename, int start)
213-
214-
This is a simplified interface to :c:func:`PyParser_SimpleParseFileFlags` below,
215-
leaving *flags* set to ``0``.
216-
217-
218-
.. c:function:: struct _node* PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int flags)
219-
220-
Similar to :c:func:`PyParser_SimpleParseStringFlagsFilename`, but the Python
221-
source code is read from *fp* instead of an in-memory string.
222-
223-
224188
.. c:function:: PyObject* PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals)
225189
226190
This is a simplified interface to :c:func:`PyRun_StringFlags` below, leaving

Doc/data/refcounts.dat

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,32 +1791,6 @@ PyObject_TypeCheck:int:::
17911791
PyObject_TypeCheck:PyObject*:o:0:
17921792
PyObject_TypeCheck:PyTypeObject*:type:0:
17931793

1794-
PyParser_SimpleParseFile:struct _node*:::
1795-
PyParser_SimpleParseFile:FILE*:fp::
1796-
PyParser_SimpleParseFile:const char*:filename::
1797-
PyParser_SimpleParseFile:int:start::
1798-
1799-
PyParser_SimpleParseFileFlags:struct _node*:::
1800-
PyParser_SimpleParseFileFlags:FILE*:fp::
1801-
PyParser_SimpleParseFileFlags:const char*:filename::
1802-
PyParser_SimpleParseFileFlags:int:start::
1803-
PyParser_SimpleParseFileFlags:int:flags::
1804-
1805-
PyParser_SimpleParseString:struct _node*:::
1806-
PyParser_SimpleParseString:const char*:str::
1807-
PyParser_SimpleParseString:int:start::
1808-
1809-
PyParser_SimpleParseStringFlags:struct _node*:::
1810-
PyParser_SimpleParseStringFlags:const char*:str::
1811-
PyParser_SimpleParseStringFlags:int:start::
1812-
PyParser_SimpleParseStringFlags:int:flags::
1813-
1814-
PyParser_SimpleParseStringFlagsFilename:struct _node*:::
1815-
PyParser_SimpleParseStringFlagsFilename:const char*:str::
1816-
PyParser_SimpleParseStringFlagsFilename:const char*:filename::
1817-
PyParser_SimpleParseStringFlagsFilename:int:start::
1818-
PyParser_SimpleParseStringFlagsFilename:int:flags::
1819-
18201794
PyRun_AnyFile:int:::
18211795
PyRun_AnyFile:FILE*:fp::
18221796
PyRun_AnyFile:const char*:filename::

Doc/faq/design.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,15 @@ bindings are resolved at run-time in Python, and the second version only needs
708708
to perform the resolution once.
709709

710710

711+
Why don't generators support the with statement?
712+
------------------------------------------------
713+
714+
For technical reasons, a generator used directly as a context manager
715+
would not work correctly. When, as is most common, a generator is used as
716+
an iterator run to completion, no closing is needed. When it is, wrap
717+
it as "contextlib.closing(generator)" in the 'with' statment.
718+
719+
711720
Why are colons required for the if/while/def/class statements?
712721
--------------------------------------------------------------
713722

Doc/faq/extending.rst

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -275,39 +275,8 @@ for more hints.
275275

276276
However sometimes you have to run the embedded Python interpreter in the same
277277
thread as your rest application and you can't allow the
278-
:c:func:`PyRun_InteractiveLoop` to stop while waiting for user input. The one
279-
solution then is to call :c:func:`PyParser_ParseString` and test for ``e.error``
280-
equal to ``E_EOF``, which means the input is incomplete. Here's a sample code
281-
fragment, untested, inspired by code from Alex Farber::
282-
283-
#define PY_SSIZE_T_CLEAN
284-
#include <Python.h>
285-
#include <node.h>
286-
#include <errcode.h>
287-
#include <grammar.h>
288-
#include <parsetok.h>
289-
#include <compile.h>
290-
291-
int testcomplete(char *code)
292-
/* code should end in \n */
293-
/* return -1 for error, 0 for incomplete, 1 for complete */
294-
{
295-
node *n;
296-
perrdetail e;
297-
298-
n = PyParser_ParseString(code, &_PyParser_Grammar,
299-
Py_file_input, &e);
300-
if (n == NULL) {
301-
if (e.error == E_EOF)
302-
return 0;
303-
return -1;
304-
}
305-
306-
PyNode_Free(n);
307-
return 1;
308-
}
309-
310-
Another solution is trying to compile the received string with
278+
:c:func:`PyRun_InteractiveLoop` to stop while waiting for user input.
279+
A solution is trying to compile the received string with
311280
:c:func:`Py_CompileString`. If it compiles without errors, try to execute the
312281
returned code object by calling :c:func:`PyEval_EvalCode`. Otherwise save the
313282
input for later. If the compilation fails, find out if it's an error or just

Doc/library/atexit.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal error is detected, or when :func:`os._exit` is called.
3939

4040
If an exception is raised during execution of the exit handlers, a traceback is
4141
printed (unless :exc:`SystemExit` is raised) and the exception information is
42-
saved. After all exit handlers have had a chance to run the last exception to
42+
saved. After all exit handlers have had a chance to run, the last exception to
4343
be raised is re-raised.
4444

4545
This function returns *func*, which makes it possible to use it as a
@@ -73,7 +73,7 @@ automatically when the program terminates without relying on the application
7373
making an explicit call into this module at termination. ::
7474

7575
try:
76-
with open("counterfile") as infile:
76+
with open('counterfile') as infile:
7777
_count = int(infile.read())
7878
except FileNotFoundError:
7979
_count = 0
@@ -83,21 +83,22 @@ making an explicit call into this module at termination. ::
8383
_count = _count + n
8484

8585
def savecounter():
86-
with open("counterfile", "w") as outfile:
87-
outfile.write("%d" % _count)
86+
with open('counterfile', 'w') as outfile:
87+
outfile.write('%d' % _count)
8888

8989
import atexit
90+
9091
atexit.register(savecounter)
9192

9293
Positional and keyword arguments may also be passed to :func:`register` to be
9394
passed along to the registered function when it is called::
9495

9596
def goodbye(name, adjective):
96-
print('Goodbye, %s, it was %s to meet you.' % (name, adjective))
97+
print('Goodbye %s, it was %s to meet you.' % (name, adjective))
9798

9899
import atexit
99-
atexit.register(goodbye, 'Donny', 'nice')
100100

101+
atexit.register(goodbye, 'Donny', 'nice')
101102
# or:
102103
atexit.register(goodbye, adjective='nice', name='Donny')
103104

@@ -107,6 +108,6 @@ Usage as a :term:`decorator`::
107108

108109
@atexit.register
109110
def goodbye():
110-
print("You are now leaving the Python sector.")
111+
print('You are now leaving the Python sector.')
111112

112113
This only works with functions that can be called without arguments.

Doc/library/collections.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,9 @@ stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``,
707707
:class:`defaultdict` objects
708708
----------------------------
709709

710-
.. class:: defaultdict([default_factory[, ...]])
710+
.. class:: defaultdict(default_factory=None, /, [...])
711711

712-
Returns a new dictionary-like object. :class:`defaultdict` is a subclass of the
712+
Return a new dictionary-like object. :class:`defaultdict` is a subclass of the
713713
built-in :class:`dict` class. It overrides one method and adds one writable
714714
instance variable. The remaining functionality is the same as for the
715715
:class:`dict` class and is not documented here.

Doc/library/faulthandler.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ Fault handler state
7676
.. versionchanged:: 3.6
7777
On Windows, a handler for Windows exception is also installed.
7878

79+
.. versionchanged:: 3.10
80+
The dump now mentions if a garbage collector collection is running
81+
if *all_threads* is true.
82+
7983
.. function:: disable()
8084

8185
Disable the fault handler: uninstall the signal handlers installed by

Doc/library/inspect.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,10 +1450,6 @@ the following flags:
14501450
The flag is set when the code object is a generator function, i.e.
14511451
a generator object is returned when the code object is executed.
14521452

1453-
.. data:: CO_NOFREE
1454-
1455-
The flag is set if there are no free or cell variables.
1456-
14571453
.. data:: CO_COROUTINE
14581454

14591455
The flag is set when the code object is a coroutine function.

0 commit comments

Comments
 (0)