Skip to content

Commit 53d33a1

Browse files
committed
Merge branch 'main' into typedocs
* main: (103 commits) pythongh-100248: Add missing `ssl_shutdown_timeout` parameter in `asyncio` docs (python#100249) Assorted minor fixes for specialization stats. (pythonGH-100219) pythongh-100176: venv: Remove redundant compat code for Python <= 3.2 (python#100177) pythonGH-100222: Redefine _Py_CODEUNIT as a union to clarify structure of code unit. (pythonGH-100223) pythongh-99955: undef ERROR and SUCCESS before redefining (fixes sanitizer warning) (python#100215) pythonGH-100206: use versionadded for the addition of sysconfig.get_default_scheme (python#100207) pythongh-81057: Move _Py_RefTotal to the "Ignored Globals" List (pythongh-100203) pythongh-81057: Move Signal-Related Globals to _PyRuntimeState (pythongh-100085) pythongh-81057: Move faulthandler Globals to _PyRuntimeState (pythongh-100152) pythongh-81057: Move tracemalloc Globals to _PyRuntimeState (pythongh-100151) pythonGH-100143: Improve collecting pystats for parts of runs (pythonGH-100144) pythongh-99955: standardize return values of functions in compiler's code-gen (python#100010) pythongh-79218: Define `MS_WIN64` macro for Mingw-w64 64bit on Windows (pythonGH-100137) Fix: typo (Indention) (pythonGH-99904) pythongh-96715 Remove redundant NULL check in `profile_trampoline` function (python#96716) pythongh-100176: remove incorrect version compatibility check from argument clinic (python#100190) clarify the 4300-digit limit on int-str conversion (python#100175) pythongh-70393: Clarify mention of "middle" scope (python#98839) pythongh-99688: Fix outdated tests in test_unary (python#99712) pythongh-100174: [Enum] Correct PowersOfThree example. (pythonGH-100178) ...
2 parents 970b03e + 9663853 commit 53d33a1

File tree

328 files changed

+7748
-4588
lines changed

Some content is hidden

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

328 files changed

+7748
-4588
lines changed

Doc/_static/og-image.png

14.2 KB
Loading

Doc/c-api/code.rst

+48
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,51 @@ bound into a function.
115115
the free variables. On error, ``NULL`` is returned and an exception is raised.
116116
117117
.. versionadded:: 3.11
118+
119+
.. c:function:: int PyCode_AddWatcher(PyCode_WatchCallback callback)
120+
121+
Register *callback* as a code object watcher for the current interpreter.
122+
Return an ID which may be passed to :c:func:`PyCode_ClearWatcher`.
123+
In case of error (e.g. no more watcher IDs available),
124+
return ``-1`` and set an exception.
125+
126+
.. versionadded:: 3.12
127+
128+
.. c:function:: int PyCode_ClearWatcher(int watcher_id)
129+
130+
Clear watcher identified by *watcher_id* previously returned from
131+
:c:func:`PyCode_AddWatcher` for the current interpreter.
132+
Return ``0`` on success, or ``-1`` and set an exception on error
133+
(e.g. if the given *watcher_id* was never registered.)
134+
135+
.. versionadded:: 3.12
136+
137+
.. c:type:: PyCodeEvent
138+
139+
Enumeration of possible code object watcher events:
140+
- ``PY_CODE_EVENT_CREATE``
141+
- ``PY_CODE_EVENT_DESTROY``
142+
143+
.. versionadded:: 3.12
144+
145+
.. c:type:: int (*PyCode_WatchCallback)(PyCodeEvent event, PyCodeObject* co)
146+
147+
Type of a code object watcher callback function.
148+
149+
If *event* is ``PY_CODE_EVENT_CREATE``, then the callback is invoked
150+
after `co` has been fully initialized. Otherwise, the callback is invoked
151+
before the destruction of *co* takes place, so the prior state of *co*
152+
can be inspected.
153+
154+
Users of this API should not rely on internal runtime implementation
155+
details. Such details may include, but are not limited to, the exact
156+
order and timing of creation and destruction of code objects. While
157+
changes in these details may result in differences observable by watchers
158+
(including whether a callback is invoked or not), it does not change
159+
the semantics of the Python code being executed.
160+
161+
If the callback returns with an exception set, it must return ``-1``; this
162+
exception will be printed as an unraisable exception using
163+
:c:func:`PyErr_WriteUnraisable`. Otherwise it should return ``0``.
164+
165+
.. versionadded:: 3.12

Doc/c-api/refcounting.rst

+44-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
Reference Counting
88
******************
99

10-
The macros in this section are used for managing reference counts of Python
11-
objects.
10+
The functions and macros in this section are used for managing reference counts
11+
of Python objects.
1212

1313

1414
.. c:function:: Py_ssize_t Py_REFCNT(PyObject *o)
@@ -129,6 +129,11 @@ objects.
129129
It is a good idea to use this macro whenever decrementing the reference
130130
count of an object that might be traversed during garbage collection.
131131
132+
.. versionchanged:: 3.12
133+
The macro argument is now only evaluated once. If the argument has side
134+
effects, these are no longer duplicated.
135+
136+
132137
.. c:function:: void Py_IncRef(PyObject *o)
133138
134139
Increment the reference count for object *o*. A function version of :c:func:`Py_XINCREF`.
@@ -139,3 +144,40 @@ objects.
139144
140145
Decrement the reference count for object *o*. A function version of :c:func:`Py_XDECREF`.
141146
It can be used for runtime dynamic embedding of Python.
147+
148+
149+
.. c:macro:: Py_SETREF(dst, src)
150+
151+
Macro safely decrementing the `dst` reference count and setting `dst` to
152+
`src`.
153+
154+
As in case of :c:func:`Py_CLEAR`, "the obvious" code can be deadly::
155+
156+
Py_DECREF(dst);
157+
dst = src;
158+
159+
The safe way is::
160+
161+
Py_SETREF(dst, src);
162+
163+
That arranges to set `dst` to `src` _before_ decrementing reference count of
164+
*dst* old value, so that any code triggered as a side-effect of `dst`
165+
getting torn down no longer believes `dst` points to a valid object.
166+
167+
.. versionadded:: 3.6
168+
169+
.. versionchanged:: 3.12
170+
The macro arguments are now only evaluated once. If an argument has side
171+
effects, these are no longer duplicated.
172+
173+
174+
.. c:macro:: Py_XSETREF(dst, src)
175+
176+
Variant of :c:macro:`Py_SETREF` macro that uses :c:func:`Py_XDECREF` instead
177+
of :c:func:`Py_DECREF`.
178+
179+
.. versionadded:: 3.6
180+
181+
.. versionchanged:: 3.12
182+
The macro arguments are now only evaluated once. If an argument has side
183+
effects, these are no longer duplicated.

Doc/conf.py

+38-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,25 @@
1313
# General configuration
1414
# ---------------------
1515

16-
extensions = ['sphinx.ext.coverage', 'sphinx.ext.doctest',
17-
'pyspecific', 'c_annotations', 'escape4chm',
18-
'asdl_highlight', 'peg_highlight', 'glossary_search']
16+
extensions = [
17+
'asdl_highlight',
18+
'c_annotations',
19+
'escape4chm',
20+
'glossary_search',
21+
'peg_highlight',
22+
'pyspecific',
23+
'sphinx.ext.coverage',
24+
'sphinx.ext.doctest',
25+
]
26+
27+
# Skip if downstream redistributors haven't installed it
28+
try:
29+
import sphinxext.opengraph
30+
except ImportError:
31+
pass
32+
else:
33+
extensions.append('sphinxext.opengraph')
34+
1935

2036
doctest_global_setup = '''
2137
try:
@@ -89,6 +105,14 @@
89105
# Short title used e.g. for <title> HTML tags.
90106
html_short_title = '%s Documentation' % release
91107

108+
# Deployment preview information, from Netlify
109+
# (See netlify.toml and https://docs.netlify.com/configure-builds/environment-variables/#git-metadata)
110+
html_context = {
111+
"is_deployment_preview": os.getenv("IS_DEPLOYMENT_PREVIEW"),
112+
"repository_url": os.getenv("REPOSITORY_URL"),
113+
"pr_id": os.getenv("REVIEW_ID")
114+
}
115+
92116
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
93117
# using the given strftime format.
94118
html_last_updated_fmt = '%b %d, %Y'
@@ -114,7 +138,7 @@
114138
html_use_opensearch = 'https://docs.python.org/' + version
115139

116140
# Additional static files.
117-
html_static_path = ['tools/static']
141+
html_static_path = ['_static', 'tools/static']
118142

119143
# Output file base name for HTML help builder.
120144
htmlhelp_basename = 'python' + release.replace('.', '')
@@ -238,3 +262,13 @@
238262
# Relative filename of the data files
239263
refcount_file = 'data/refcounts.dat'
240264
stable_abi_file = 'data/stable_abi.dat'
265+
266+
# sphinxext-opengraph config
267+
ogp_site_url = 'https://docs.python.org/3/'
268+
ogp_site_name = 'Python documentation'
269+
ogp_image = '_static/og-image.png'
270+
ogp_custom_meta_tags = [
271+
'<meta property="og:image:width" content="200">',
272+
'<meta property="og:image:height" content="200">',
273+
'<meta name="theme-color" content="#3776ab">',
274+
]

Doc/howto/enum.rst

+27
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ And a function to display the chores for a given day::
158158
... for chore, days in chores.items():
159159
... if day in days:
160160
... print(chore)
161+
...
161162
>>> show_chores(chores_for_ethan, Weekday.SATURDAY)
162163
answer SO questions
163164

@@ -459,6 +460,31 @@ sense to allow sharing some common behavior between a group of enumerations.
459460
(See `OrderedEnum`_ for an example.)
460461

461462

463+
.. _enum-dataclass-support:
464+
465+
Dataclass support
466+
-----------------
467+
468+
When inheriting from a :class:`~dataclasses.dataclass`,
469+
the :meth:`~Enum.__repr__` omits the inherited class' name. For example::
470+
471+
>>> @dataclass
472+
... class CreatureDataMixin:
473+
... size: str
474+
... legs: int
475+
... tail: bool = field(repr=False, default=True)
476+
...
477+
>>> class Creature(CreatureDataMixin, Enum):
478+
... BEETLE = 'small', 6
479+
... DOG = 'medium', 4
480+
...
481+
>>> Creature.DOG
482+
<Creature.DOG: size='medium', legs=4>
483+
484+
Use the :func:`!dataclass` argument ``repr=False``
485+
to use the standard :func:`repr`.
486+
487+
462488
Pickling
463489
--------
464490

@@ -687,6 +713,7 @@ It is also possible to name the combinations::
687713
... W = 2
688714
... X = 1
689715
... RWX = 7
716+
...
690717
>>> Perm.RWX
691718
<Perm.RWX: 7>
692719
>>> ~Perm.RWX

Doc/library/argparse.rst

+1
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ arguments they contain. For example::
565565

566566
>>> with open('args.txt', 'w', encoding=sys.getfilesystemencoding()) as fp:
567567
... fp.write('-f\nbar')
568+
...
568569
>>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
569570
>>> parser.add_argument('-f')
570571
>>> parser.parse_args(['-f', 'foo', '@args.txt'])

Doc/library/asyncio-eventloop.rst

+17-12
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ an event loop:
3333

3434
Return the running event loop in the current OS thread.
3535

36-
If there is no running event loop a :exc:`RuntimeError` is raised.
36+
Raise a :exc:`RuntimeError` if there is no running event loop.
37+
3738
This function can only be called from a coroutine or a callback.
3839

3940
.. versionadded:: 3.7
@@ -42,27 +43,31 @@ an event loop:
4243

4344
Get the current event loop.
4445

45-
If there is no current event loop set in the current OS thread,
46-
the OS thread is main, and :func:`set_event_loop` has not yet
47-
been called, asyncio will create a new event loop and set it as the
48-
current one.
46+
When called from a coroutine or a callback (e.g. scheduled with
47+
call_soon or similar API), this function will always return the
48+
running event loop.
49+
50+
If there is no running event loop set, the function will return
51+
the result of calling ``get_event_loop_policy().get_event_loop()``.
4952

5053
Because this function has rather complex behavior (especially
5154
when custom event loop policies are in use), using the
5255
:func:`get_running_loop` function is preferred to :func:`get_event_loop`
5356
in coroutines and callbacks.
5457

55-
Consider also using the :func:`asyncio.run` function instead of using
56-
lower level functions to manually create and close an event loop.
58+
As noted above, consider using the higher-level :func:`asyncio.run` function,
59+
instead of using these lower level functions to manually create and close an
60+
event loop.
5761

58-
.. deprecated:: 3.10
59-
Deprecation warning is emitted if there is no running event loop.
60-
In future Python releases, this function will be an alias of
61-
:func:`get_running_loop`.
62+
.. note::
63+
In Python versions 3.10.0--3.10.8 and 3.11.0 this function
64+
(and other functions which used it implicitly) emitted a
65+
:exc:`DeprecationWarning` if there was no running event loop, even if
66+
the current loop was set.
6267

6368
.. function:: set_event_loop(loop)
6469

65-
Set *loop* as a current event loop for the current OS thread.
70+
Set *loop* as the current event loop for the current OS thread.
6671

6772
.. function:: new_event_loop()
6873

Doc/library/asyncio-llapi-index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Obtaining the Event Loop
1919
- The **preferred** function to get the running event loop.
2020

2121
* - :func:`asyncio.get_event_loop`
22-
- Get an event loop instance (current or via the policy).
22+
- Get an event loop instance (running or current via the current policy).
2323

2424
* - :func:`asyncio.set_event_loop`
2525
- Set the event loop as current via the current policy.

Doc/library/asyncio-policy.rst

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ asyncio ships with the following built-in policies:
116116

117117
On Windows, :class:`ProactorEventLoop` is now used by default.
118118

119+
.. versionchanged:: 3.12
120+
:meth:`get_event_loop` now raises a :exc:`RuntimeError` if there is no
121+
current event loop set.
122+
119123

120124
.. class:: WindowsSelectorEventLoopPolicy
121125

Doc/library/asyncio-stream.rst

+17-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ and work with streams:
5252
limit=None, ssl=None, family=0, proto=0, \
5353
flags=0, sock=None, local_addr=None, \
5454
server_hostname=None, ssl_handshake_timeout=None, \
55+
ssl_shutdown_timeout=None, \
5556
happy_eyeballs_delay=None, interleave=None)
5657

5758
Establish a network connection and return a pair of
@@ -82,14 +83,17 @@ and work with streams:
8283
.. versionchanged:: 3.10
8384
Removed the *loop* parameter.
8485

86+
.. versionchanged:: 3.11
87+
Added the *ssl_shutdown_timeout* parameter.
88+
8589

8690
.. coroutinefunction:: start_server(client_connected_cb, host=None, \
8791
port=None, *, limit=None, \
8892
family=socket.AF_UNSPEC, \
8993
flags=socket.AI_PASSIVE, sock=None, \
9094
backlog=100, ssl=None, reuse_address=None, \
9195
reuse_port=None, ssl_handshake_timeout=None, \
92-
start_serving=True)
96+
ssl_shutdown_timeout=None, start_serving=True)
9397
9498
Start a socket server.
9599

@@ -121,12 +125,15 @@ and work with streams:
121125
.. versionchanged:: 3.10
122126
Removed the *loop* parameter.
123127

128+
.. versionchanged:: 3.11
129+
Added the *ssl_shutdown_timeout* parameter.
130+
124131

125132
.. rubric:: Unix Sockets
126133

127134
.. coroutinefunction:: open_unix_connection(path=None, *, limit=None, \
128135
ssl=None, sock=None, server_hostname=None, \
129-
ssl_handshake_timeout=None)
136+
ssl_handshake_timeout=None, ssl_shutdown_timeout=None)
130137

131138
Establish a Unix socket connection and return a pair of
132139
``(reader, writer)``.
@@ -150,10 +157,14 @@ and work with streams:
150157
.. versionchanged:: 3.10
151158
Removed the *loop* parameter.
152159

160+
.. versionchanged:: 3.11
161+
Added the *ssl_shutdown_timeout* parameter.
162+
153163

154164
.. coroutinefunction:: start_unix_server(client_connected_cb, path=None, \
155165
*, limit=None, sock=None, backlog=100, ssl=None, \
156-
ssl_handshake_timeout=None, start_serving=True)
166+
ssl_handshake_timeout=None, \
167+
ssl_shutdown_timeout=None, start_serving=True)
157168
158169
Start a Unix socket server.
159170

@@ -176,6 +187,9 @@ and work with streams:
176187
.. versionchanged:: 3.10
177188
Removed the *loop* parameter.
178189

190+
.. versionchanged:: 3.11
191+
Added the *ssl_shutdown_timeout* parameter.
192+
179193

180194
StreamReader
181195
============

Doc/library/bz2.rst

+2
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,11 @@ Writing and reading a bzip2-compressed file in binary mode:
320320
>>> with bz2.open("myfile.bz2", "wb") as f:
321321
... # Write compressed data to file
322322
... unused = f.write(data)
323+
...
323324
>>> with bz2.open("myfile.bz2", "rb") as f:
324325
... # Decompress data from file
325326
... content = f.read()
327+
...
326328
>>> content == data # Check equality to original object after round-trip
327329
True
328330

0 commit comments

Comments
 (0)