Skip to content

Commit cadeecb

Browse files
authored
Merge branch 'main' into gh-99726
2 parents 768ba42 + b7e4f1d commit cadeecb

File tree

277 files changed

+5213
-3577
lines changed

Some content is hidden

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

277 files changed

+5213
-3577
lines changed

Doc/_static/og-image.png

14.2 KB
Loading

Doc/c-api/refcounting.rst

Lines changed: 44 additions & 2 deletions
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/c-api/typeobj.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ Quick Reference
147147
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
148148
| :c:member:`~PyTypeObject.tp_vectorcall` | :c:type:`vectorcallfunc` | | | | | |
149149
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
150+
| :c:member:`~PyTypeObject.tp_watched` | char | | | | | |
151+
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
150152

151153
.. [#slots]
152154
@@ -2090,6 +2092,13 @@ and :c:type:`PyType_Type` effectively act as defaults.)
20902092
.. versionadded:: 3.9 (the field exists since 3.8 but it's only used since 3.9)
20912093

20922094

2095+
.. c:member:: char PyTypeObject.tp_watched
2096+
2097+
Internal. Do not use.
2098+
2099+
.. versionadded:: 3.12
2100+
2101+
20932102
.. _static-types:
20942103

20952104
Static Types

Doc/conf.py

Lines changed: 38 additions & 4 deletions
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

Lines changed: 27 additions & 0 deletions
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/includes/typestruct.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,7 @@ typedef struct _typeobject {
8080

8181
destructor tp_finalize;
8282
vectorcallfunc tp_vectorcall;
83+
84+
/* bitset of which type-watchers care about this type */
85+
char tp_watched;
8386
} PyTypeObject;

Doc/library/argparse.rst

Lines changed: 1 addition & 0 deletions
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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ an event loop:
4343

4444
Get the current event loop.
4545

46-
If there is no current event loop set in the current OS thread,
47-
the OS thread is main, and :func:`set_event_loop` has not yet
48-
been called, asyncio will create a new event loop and set it as the
49-
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()``.
5052

5153
Because this function has rather complex behavior (especially
5254
when custom event loop policies are in use), using the
@@ -57,11 +59,11 @@ an event loop:
5759
instead of using these lower level functions to manually create and close an
5860
event loop.
5961

60-
.. deprecated:: 3.10
61-
Emits a deprecation warning if there is no running event loop.
62-
In future Python releases, this function may become an alias of
63-
:func:`get_running_loop` and will accordingly raise a
64-
:exc:`RuntimeError` if there is no running event 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.
6567

6668
.. function:: set_event_loop(loop)
6769

Doc/library/asyncio-llapi-index.rst

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 17 additions & 3 deletions
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

Lines changed: 2 additions & 0 deletions
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

Doc/library/collections.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ For example::
229229
>>> cnt = Counter()
230230
>>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
231231
... cnt[word] += 1
232+
...
232233
>>> cnt
233234
Counter({'blue': 3, 'red': 2, 'green': 1})
234235

@@ -818,6 +819,7 @@ zero):
818819

819820
>>> def constant_factory(value):
820821
... return lambda: value
822+
...
821823
>>> d = defaultdict(constant_factory('<missing>'))
822824
>>> d.update(name='John', action='ran')
823825
>>> '%(name)s %(action)s to %(object)s' % d

Doc/library/datetime.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ Example of counting days to an event::
765765
>>> my_birthday = date(today.year, 6, 24)
766766
>>> if my_birthday < today:
767767
... my_birthday = my_birthday.replace(year=today.year + 1)
768+
...
768769
>>> my_birthday
769770
datetime.date(2008, 6, 24)
770771
>>> time_to_birthday = abs(my_birthday - today)
@@ -2601,7 +2602,7 @@ Notes:
26012602

26022603
(9)
26032604
When used with the :meth:`strptime` method, the leading zero is optional
2604-
for formats ``%d``, ``%m``, ``%H``, ``%I``, ``%M``, ``%S``, ``%J``, ``%U``,
2605+
for formats ``%d``, ``%m``, ``%H``, ``%I``, ``%M``, ``%S``, ``%j``, ``%U``,
26052606
``%W``, and ``%V``. Format ``%y`` does require a leading zero.
26062607

26072608
.. rubric:: Footnotes

Doc/library/decimal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,7 @@ to handle the :meth:`quantize` step:
20572057

20582058
>>> def mul(x, y, fp=TWOPLACES):
20592059
... return (x * y).quantize(fp)
2060+
...
20602061
>>> def div(x, y, fp=TWOPLACES):
20612062
... return (x / y).quantize(fp)
20622063

0 commit comments

Comments
 (0)