Skip to content

Commit 4ac8e66

Browse files
Deploy preview for PR 1193 🛫
1 parent bc72aab commit 4ac8e66

File tree

577 files changed

+1044
-766
lines changed

Some content is hidden

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

577 files changed

+1044
-766
lines changed

pr-preview/pr-1193/_sources/c-api/intro.rst.txt

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,35 @@ complete listing.
127127

128128
.. versionadded:: 3.3
129129

130+
.. c:macro:: Py_ALIGNED(num)
131+
132+
Specify alignment to *num* bytes on compilers that support it.
133+
134+
Consider using the C11 standard ``_Alignas`` specifier over this macro.
135+
136+
.. c:macro:: Py_ARITHMETIC_RIGHT_SHIFT(type, integer, positions)
137+
138+
Similar to ``integer >> positions``, but forces sign extension, as the C
139+
standard does not define whether a right-shift of a signed integer will
140+
perform sign extension or a zero-fill.
141+
142+
*integer* should be any signed integer type.
143+
*positions* is the number of positions to shift to the right.
144+
145+
Both *integer* and *positions* can be evaluated more than once;
146+
consequently, avoid directly passing a function call or some other
147+
operation with side-effects to this macro. Instead, store the result as a
148+
variable and then pass it.
149+
150+
*type* is unused and only kept for backwards compatibility. Historically,
151+
*type* was used to cast *integer*.
152+
153+
.. versionchanged:: 3.1
154+
155+
This macro is now valid for all signed integer types, not just those for
156+
which ``unsigned type`` is legal. As a result, *type* is no longer
157+
used.
158+
130159
.. c:macro:: Py_ALWAYS_INLINE
131160
132161
Ask the compiler to always inline a static inline function. The compiler can
@@ -149,6 +178,15 @@ complete listing.
149178

150179
.. versionadded:: 3.11
151180

181+
.. c:macro:: Py_CAN_START_THREADS
182+
183+
If this macro is defined, then the current system is able to start threads.
184+
185+
Currently, all systems supported by CPython (per :pep:`11`), with the
186+
exception of some WebAssembly platforms, support starting threads.
187+
188+
.. versionadded:: 3.13
189+
152190
.. c:macro:: Py_CHARMASK(c)
153191
154192
Argument must be a character or an integer in the range [-128, 127] or [0,
@@ -166,11 +204,35 @@ complete listing.
166204
.. versionchanged:: 3.8
167205
MSVC support was added.
168206

207+
.. c:macro:: Py_FORCE_EXPANSION(X)
208+
209+
This is equivalent to ``X``, which is useful for token-pasting in
210+
macros, as macro expansions in *X* are forcefully evaluated by the
211+
preprocessor.
212+
213+
.. c:macro:: Py_GCC_ATTRIBUTE(name)
214+
215+
Use a GCC attribute *name*, hiding it from compilers that don't support GCC
216+
attributes (such as MSVC).
217+
218+
This expands to ``__attribute__((name))`` on a GCC compiler, and expands
219+
to nothing on compilers that don't support GCC attributes.
220+
169221
.. c:macro:: Py_GETENV(s)
170222
171223
Like ``getenv(s)``, but returns ``NULL`` if :option:`-E` was passed on the
172224
command line (see :c:member:`PyConfig.use_environment`).
173225

226+
.. c:macro:: Py_LL(number)
227+
228+
Use *number* as a ``long long`` integer literal.
229+
230+
This usally expands to *number* followed by ``LL``, but will expand to some
231+
compiler-specific suffixes (such as ``I64``) on older compilers.
232+
233+
In modern versions of Python, this macro is not very useful, as C99 and
234+
later require the ``LL`` suffix to be valid for an integer.
235+
174236
.. c:macro:: Py_LOCAL(type)
175237
176238
Declare a function returning the specified *type* using a fast-calling
@@ -228,13 +290,37 @@ complete listing.
228290

229291
.. versionadded:: 3.11
230292

293+
.. c:macro:: Py_SAFE_DOWNCAST(value, larger, smaller)
294+
295+
Cast *value* to type *smaller* from type *larger*, validating that no
296+
information was lost.
297+
298+
On release builds of Python, this is roughly equivalent to
299+
``(smaller) value`` (in C++, ``static_cast<smaller>(value)`` will be
300+
used instead).
301+
302+
On debug builds (implying that :c:macro:`Py_DEBUG` is defined), this asserts
303+
that no information was lost with the cast from *larger* to *smaller*.
304+
305+
*value*, *larger*, and *smaller* may all be evaluated more than once in the
306+
expression; consequently, do not pass an expression with side-effects directly to
307+
this macro.
308+
231309
.. c:macro:: Py_STRINGIFY(x)
232310
233311
Convert ``x`` to a C string. E.g. ``Py_STRINGIFY(123)`` returns
234312
``"123"``.
235313

236314
.. versionadded:: 3.4
237315

316+
.. c:macro:: Py_ULL(number)
317+
318+
Similar to :c:macro:`Py_LL`, but *number* will be an ``unsigned long long``
319+
literal instead. This is done by appending ``U`` to the result of ``Py_LL``.
320+
321+
In modern versions of Python, this macro is not very useful, as C99 and
322+
later require the ``ULL``/``LLU`` suffixes to be valid for an integer.
323+
238324
.. c:macro:: Py_UNREACHABLE()
239325
240326
Use this when you have a code path that cannot be reached by design.
@@ -375,6 +461,16 @@ complete listing.
375461
This macro is intended for defining CPython's C API itself;
376462
extension modules should not use it for their own symbols.
377463

464+
.. c:macro:: Py_VA_COPY
465+
466+
This is a :term:`soft deprecated` alias to the C99-standard ``va_copy``
467+
function.
468+
469+
Historically, this would use a compiler-specific method to copy a ``va_list``.
470+
471+
.. versionchanged:: 3.6
472+
This is now an alias to ``va_copy``.
473+
378474

379475
.. _api-objects:
380476

pr-preview/pr-1193/_sources/library/itertools.rst.txt

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,8 @@ and :term:`generators <generator>` which incur interpreter overhead.
845845
from contextlib import suppress
846846
from functools import reduce
847847
from math import comb, isqrt, prod, sumprod
848-
from operator import getitem, is_not, itemgetter, mul, neg
848+
from operator import getitem, is_not, itemgetter, mul, neg, truediv
849+
849850

850851
# ==== Basic one liners ====
851852

@@ -858,9 +859,10 @@ and :term:`generators <generator>` which incur interpreter overhead.
858859
# prepend(1, [2, 3, 4]) → 1 2 3 4
859860
return chain([value], iterable)
860861

861-
def tabulate(function, start=0):
862-
"Return function(0), function(1), ..."
863-
return map(function, count(start))
862+
def running_mean(iterable):
863+
"Yield the average of all values seen so far."
864+
# running_mean([8.5, 9.5, 7.5, 6.5]) -> 8.5 9.0 8.5 8.0
865+
return map(truediv, accumulate(iterable), count(1))
864866

865867
def repeatfunc(function, times=None, *args):
866868
"Repeat calls to a function with specified arguments."
@@ -913,6 +915,7 @@ and :term:`generators <generator>` which incur interpreter overhead.
913915
# all_equal('4٤௪౪໔', key=int) → True
914916
return len(take(2, groupby(iterable, key))) <= 1
915917

918+
916919
# ==== Data pipelines ====
917920

918921
def unique_justseen(iterable, key=None):
@@ -1021,6 +1024,7 @@ and :term:`generators <generator>` which incur interpreter overhead.
10211024
while True:
10221025
yield function()
10231026

1027+
10241028
# ==== Mathematical operations ====
10251029

10261030
def multinomial(*counts):
@@ -1040,6 +1044,7 @@ and :term:`generators <generator>` which incur interpreter overhead.
10401044
# sum_of_squares([10, 20, 30]) → 1400
10411045
return sumprod(*tee(iterable))
10421046
1047+
10431048
# ==== Matrix operations ====
10441049

10451050
def reshape(matrix, columns):
@@ -1058,6 +1063,7 @@ and :term:`generators <generator>` which incur interpreter overhead.
10581063
n = len(m2[0])
10591064
return batched(starmap(sumprod, product(m1, transpose(m2))), n)
10601065

1066+
10611067
# ==== Polynomial arithmetic ====
10621068

10631069
def convolve(signal, kernel):
@@ -1114,6 +1120,7 @@ and :term:`generators <generator>` which incur interpreter overhead.
11141120
powers = reversed(range(1, n))
11151121
return list(map(mul, coefficients, powers))
11161122

1123+
11171124
# ==== Number theory ====
11181125

11191126
def sieve(n):
@@ -1230,8 +1237,8 @@ and :term:`generators <generator>` which incur interpreter overhead.
12301237
[(0, 'a'), (1, 'b'), (2, 'c')]
12311238

12321239

1233-
>>> list(islice(tabulate(lambda x: 2*x), 4))
1234-
[0, 2, 4, 6]
1240+
>>> list(running_mean([8.5, 9.5, 7.5, 6.5]))
1241+
[8.5, 9.0, 8.5, 8.0]
12351242

12361243

12371244
>>> for _ in loops(5):
@@ -1798,6 +1805,10 @@ and :term:`generators <generator>` which incur interpreter overhead.
17981805

17991806
# Old recipes and their tests which are guaranteed to continue to work.
18001807

1808+
def tabulate(function, start=0):
1809+
"Return function(0), function(1), ..."
1810+
return map(function, count(start))
1811+
18011812
def old_sumprod_recipe(vec1, vec2):
18021813
"Compute a sum of products."
18031814
return sum(starmap(operator.mul, zip(vec1, vec2, strict=True)))
@@ -1877,6 +1888,10 @@ and :term:`generators <generator>` which incur interpreter overhead.
18771888
.. doctest::
18781889
:hide:
18791890

1891+
>>> list(islice(tabulate(lambda x: 2*x), 4))
1892+
[0, 2, 4, 6]
1893+
1894+
18801895
>>> dotproduct([1,2,3], [4,5,6])
18811896
32
18821897

pr-preview/pr-1193/_sources/library/stdtypes.rst.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,6 +2751,19 @@ expression support in the :mod:`re` module).
27512751
test string beginning at that position. With optional *end*, stop comparing
27522752
string at that position.
27532753

2754+
For example:
2755+
2756+
.. doctest::
2757+
2758+
>>> 'Python'.startswith('Py')
2759+
True
2760+
>>> 'a tuple of prefixes'.startswith(('at', 'a'))
2761+
True
2762+
>>> 'Python is amazing'.startswith('is', 7)
2763+
True
2764+
2765+
See also :meth:`endswith` and :meth:`removeprefix`.
2766+
27542767

27552768
.. method:: str.strip(chars=None, /)
27562769

pr-preview/pr-1193/_sources/library/urllib.robotparser.rst.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ class::
9191

9292
>>> import urllib.robotparser
9393
>>> rp = urllib.robotparser.RobotFileParser()
94-
>>> rp.set_url("http://www.musi-cal.com/robots.txt")
94+
>>> rp.set_url("http://www.pythontest.net/robots.txt")
9595
>>> rp.read()
9696
>>> rrate = rp.request_rate("*")
9797
>>> rrate.requests
98-
3
98+
1
9999
>>> rrate.seconds
100-
20
100+
1
101101
>>> rp.crawl_delay("*")
102102
6
103-
>>> rp.can_fetch("*", "http://www.musi-cal.com/cgi-bin/search?city=San+Francisco")
104-
False
105-
>>> rp.can_fetch("*", "http://www.musi-cal.com/")
103+
>>> rp.can_fetch("*", "http://www.pythontest.net/")
106104
True
105+
>>> rp.can_fetch("*", "http://www.pythontest.net/no-robots-here/")
106+
False

pr-preview/pr-1193/about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ <h3>導航</h3>
326326
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
327327
<br>
328328
<br>
329-
最後更新於 2月 04, 2026 (00:22 UTC)。
329+
最後更新於 2月 05, 2026 (00:25 UTC)。
330330

331331
<a href="/bugs.html">發現 bug</a>
332332

pr-preview/pr-1193/bugs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ <h3>導航</h3>
363363
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
364364
<br>
365365
<br>
366-
最後更新於 2月 04, 2026 (00:22 UTC)。
366+
最後更新於 2月 05, 2026 (00:25 UTC)。
367367

368368
<a href="/bugs.html">發現 bug</a>
369369

pr-preview/pr-1193/c-api/abstract.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ <h3>導航</h3>
335335
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
336336
<br>
337337
<br>
338-
最後更新於 2月 04, 2026 (00:22 UTC)。
338+
最後更新於 2月 05, 2026 (00:25 UTC)。
339339

340340
<a href="/bugs.html">發現 bug</a>
341341

pr-preview/pr-1193/c-api/allocation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ <h3>導航</h3>
544544
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
545545
<br>
546546
<br>
547-
最後更新於 2月 04, 2026 (00:22 UTC)。
547+
最後更新於 2月 05, 2026 (00:25 UTC)。
548548

549549
<a href="/bugs.html">發現 bug</a>
550550

pr-preview/pr-1193/c-api/apiabiversion.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ <h3>導航</h3>
484484
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
485485
<br>
486486
<br>
487-
最後更新於 2月 04, 2026 (00:22 UTC)。
487+
最後更新於 2月 05, 2026 (00:25 UTC)。
488488

489489
<a href="/bugs.html">發現 bug</a>
490490

pr-preview/pr-1193/c-api/arg.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ <h3>導航</h3>
966966
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
967967
<br>
968968
<br>
969-
最後更新於 2月 04, 2026 (00:22 UTC)。
969+
最後更新於 2月 05, 2026 (00:25 UTC)。
970970

971971
<a href="/bugs.html">發現 bug</a>
972972

0 commit comments

Comments
 (0)