Skip to content

Commit fe8a986

Browse files
Merge branch '3.13' into backport-27ded24-3.13
2 parents d9f479f + 7f9c369 commit fe8a986

32 files changed

Lines changed: 330 additions & 89 deletions

.pre-commit-config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ repos:
4949
types: [python]
5050
exclude: ^Tools/c-analyzer/cpython/_parser.py
5151

52+
- repo: local
53+
hooks:
54+
- id: blurb-no-space-c-api
55+
name: Check C API news entries
56+
language: fail
57+
entry: Space found in path, move to Misc/NEWS.d/next/C_API/
58+
files: Misc/NEWS.d/next/C API/20.*.rst
59+
60+
- repo: local
61+
hooks:
62+
- id: blurb-no-space-core-and-builtins
63+
name: Check Core and Builtins news entries
64+
language: fail
65+
entry: Space found in path, move to Misc/NEWS.d/next/Core_and_Builtins/
66+
files: Misc/NEWS.d/next/Core and Builtins/20.*.rst
67+
5268
- repo: https://github.com/pre-commit/pre-commit-hooks
5369
rev: v6.0.0
5470
hooks:

Doc/c-api/frame.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ See also :ref:`Reflection <reflection>`.
5050
5151
Return a :term:`strong reference`, or ``NULL`` if *frame* has no outer
5252
frame.
53+
This raises no exceptions.
5354
5455
.. versionadded:: 3.9
5556

Doc/c-api/typeobj.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,52 @@ and :c:data:`PyType_Type` effectively act as defaults.)
14141414
It will be removed in a future version of CPython
14151415

14161416

1417+
.. c:macro:: Py_TPFLAGS_HAVE_VERSION_TAG
1418+
1419+
This is a :term:`soft deprecated` macro that does nothing.
1420+
Historically, this would indicate that the
1421+
:c:member:`~PyTypeObject.tp_version_tag` field was available and
1422+
initialized.
1423+
1424+
1425+
.. c:macro:: Py_TPFLAGS_INLINE_VALUES
1426+
1427+
This bit indicates that instances of this type will have an "inline values"
1428+
array (containing the object's attributes) placed directly after the end
1429+
of the object.
1430+
1431+
This requires that :c:macro:`Py_TPFLAGS_HAVE_GC` is set.
1432+
1433+
**Inheritance:**
1434+
1435+
This flag is not inherited.
1436+
1437+
.. versionadded:: 3.13
1438+
1439+
1440+
.. c:macro:: Py_TPFLAGS_IS_ABSTRACT
1441+
1442+
This bit indicates that this is an abstract type and therefore cannot
1443+
be instantiated.
1444+
1445+
**Inheritance:**
1446+
1447+
This flag is not inherited.
1448+
1449+
.. seealso::
1450+
:mod:`abc`
1451+
1452+
1453+
.. c:macro:: Py_TPFLAGS_HAVE_STACKLESS_EXTENSION
1454+
1455+
Internal. Do not set or unset this flag.
1456+
Historically, this was a reserved flag for use in Stackless Python.
1457+
1458+
.. warning::
1459+
This flag is present in header files, but is not be used.
1460+
This may be removed in a future version of CPython.
1461+
1462+
14171463
.. c:member:: const char* PyTypeObject.tp_doc
14181464
14191465
.. corresponding-type-slot:: Py_tp_doc

Doc/library/stdtypes.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2353,6 +2353,19 @@ expression support in the :mod:`re` module).
23532353
done using the specified *fillchar* (default is an ASCII space). The
23542354
original string is returned if *width* is less than or equal to ``len(s)``.
23552355

2356+
For example:
2357+
2358+
.. doctest::
2359+
2360+
>>> 'Python'.rjust(10)
2361+
' Python'
2362+
>>> 'Python'.rjust(10, '.')
2363+
'....Python'
2364+
>>> 'Monty Python'.rjust(10, '.')
2365+
'Monty Python'
2366+
2367+
See also :meth:`ljust` and :meth:`zfill`.
2368+
23562369

23572370
.. method:: str.rpartition(sep, /)
23582371

@@ -2669,13 +2682,17 @@ expression support in the :mod:`re` module).
26692682
than before. The original string is returned if *width* is less than
26702683
or equal to ``len(s)``.
26712684

2672-
For example::
2685+
For example:
2686+
2687+
.. doctest::
26732688

26742689
>>> "42".zfill(5)
26752690
'00042'
26762691
>>> "-42".zfill(5)
26772692
'-0042'
26782693

2694+
See also :meth:`rjust`.
2695+
26792696

26802697
.. index::
26812698
single: ! formatted string literal

Lib/asyncio/windows_utils.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import msvcrt
1111
import os
1212
import subprocess
13-
import tempfile
1413
import warnings
1514

1615

@@ -24,17 +23,14 @@
2423
PIPE = subprocess.PIPE
2524
STDOUT = subprocess.STDOUT
2625
_mmap_counter = itertools.count()
26+
_MAX_PIPE_ATTEMPTS = 20
2727

2828

2929
# Replacement for os.pipe() using handles instead of fds
3030

3131

3232
def pipe(*, duplex=False, overlapped=(True, True), bufsize=BUFSIZE):
3333
"""Like os.pipe() but with overlapped support and using handles not fds."""
34-
address = tempfile.mktemp(
35-
prefix=r'\\.\pipe\python-pipe-{:d}-{:d}-'.format(
36-
os.getpid(), next(_mmap_counter)))
37-
3834
if duplex:
3935
openmode = _winapi.PIPE_ACCESS_DUPLEX
4036
access = _winapi.GENERIC_READ | _winapi.GENERIC_WRITE
@@ -56,9 +52,20 @@ def pipe(*, duplex=False, overlapped=(True, True), bufsize=BUFSIZE):
5652

5753
h1 = h2 = None
5854
try:
59-
h1 = _winapi.CreateNamedPipe(
60-
address, openmode, _winapi.PIPE_WAIT,
61-
1, obsize, ibsize, _winapi.NMPWAIT_WAIT_FOREVER, _winapi.NULL)
55+
for attempts in itertools.count():
56+
address = r'\\.\pipe\python-pipe-{:d}-{:d}-{}'.format(
57+
os.getpid(), next(_mmap_counter), os.urandom(8).hex())
58+
try:
59+
h1 = _winapi.CreateNamedPipe(
60+
address, openmode, _winapi.PIPE_WAIT,
61+
1, obsize, ibsize, _winapi.NMPWAIT_WAIT_FOREVER, _winapi.NULL)
62+
break
63+
except OSError as e:
64+
if attempts >= _MAX_PIPE_ATTEMPTS:
65+
raise
66+
if e.winerror not in (_winapi.ERROR_PIPE_BUSY,
67+
_winapi.ERROR_ACCESS_DENIED):
68+
raise
6269

6370
h2 = _winapi.CreateFile(
6471
address, access, 0, _winapi.NULL, _winapi.OPEN_EXISTING,

Lib/email/_header_value_parser.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
# Useful constants and functions
8181
#
8282

83-
WSP = set(' \t')
83+
_WSP = ' \t'
84+
WSP = set(_WSP)
8485
CFWS_LEADER = WSP | set('(')
8586
SPECIALS = set(r'()<>@,:;.\"[]')
8687
ATOM_ENDS = SPECIALS | WSP
@@ -2831,6 +2832,7 @@ def _steal_trailing_WSP_if_exists(lines):
28312832
lines.pop()
28322833
return wsp
28332834

2835+
28342836
def _refold_parse_tree(parse_tree, *, policy):
28352837
"""Return string of contents of parse_tree folded according to RFC rules.
28362838
@@ -2839,11 +2841,9 @@ def _refold_parse_tree(parse_tree, *, policy):
28392841
maxlen = policy.max_line_length or sys.maxsize
28402842
encoding = 'utf-8' if policy.utf8 else 'us-ascii'
28412843
lines = [''] # Folded lines to be output
2842-
leading_whitespace = '' # When we have whitespace between two encoded
2843-
# words, we may need to encode the whitespace
2844-
# at the beginning of the second word.
2845-
last_ew = None # Points to the last encoded character if there's an ew on
2846-
# the line
2844+
last_word_is_ew = False
2845+
last_ew = None # if there is an encoded word in the last line of lines,
2846+
# points to the encoded word's first character
28472847
last_charset = None
28482848
wrap_as_ew_blocked = 0
28492849
want_encoding = False # This is set to True if we need to encode this part
@@ -2878,6 +2878,7 @@ def _refold_parse_tree(parse_tree, *, policy):
28782878
if part.token_type == 'mime-parameters':
28792879
# Mime parameter folding (using RFC2231) is extra special.
28802880
_fold_mime_parameters(part, lines, maxlen, encoding)
2881+
last_word_is_ew = False
28812882
continue
28822883

28832884
if want_encoding and not wrap_as_ew_blocked:
@@ -2894,6 +2895,7 @@ def _refold_parse_tree(parse_tree, *, policy):
28942895
# XXX what if encoded_part has no leading FWS?
28952896
lines.append(newline)
28962897
lines[-1] += encoded_part
2898+
last_word_is_ew = False
28972899
continue
28982900
# Either this is not a major syntactic break, so we don't
28992901
# want it on a line by itself even if it fits, or it
@@ -2912,11 +2914,16 @@ def _refold_parse_tree(parse_tree, *, policy):
29122914
(last_charset == 'unknown-8bit' or
29132915
last_charset == 'utf-8' and charset != 'us-ascii')):
29142916
last_ew = None
2915-
last_ew = _fold_as_ew(tstr, lines, maxlen, last_ew,
2916-
part.ew_combine_allowed, charset, leading_whitespace)
2917-
# This whitespace has been added to the lines in _fold_as_ew()
2918-
# so clear it now.
2919-
leading_whitespace = ''
2917+
last_ew = _fold_as_ew(
2918+
tstr,
2919+
lines,
2920+
maxlen,
2921+
last_ew,
2922+
part.ew_combine_allowed,
2923+
charset,
2924+
last_word_is_ew,
2925+
)
2926+
last_word_is_ew = True
29202927
last_charset = charset
29212928
want_encoding = False
29222929
continue
@@ -2929,28 +2936,19 @@ def _refold_parse_tree(parse_tree, *, policy):
29292936

29302937
if len(tstr) <= maxlen - len(lines[-1]):
29312938
lines[-1] += tstr
2939+
last_word_is_ew = last_word_is_ew and not bool(tstr.strip(_WSP))
29322940
continue
29332941

29342942
# This part is too long to fit. The RFC wants us to break at
29352943
# "major syntactic breaks", so unless we don't consider this
29362944
# to be one, check if it will fit on the next line by itself.
2937-
leading_whitespace = ''
29382945
if (part.syntactic_break and
29392946
len(tstr) + 1 <= maxlen):
29402947
newline = _steal_trailing_WSP_if_exists(lines)
29412948
if newline or part.startswith_fws():
2942-
# We're going to fold the data onto a new line here. Due to
2943-
# the way encoded strings handle continuation lines, we need to
2944-
# be prepared to encode any whitespace if the next line turns
2945-
# out to start with an encoded word.
29462949
lines.append(newline + tstr)
2947-
2948-
whitespace_accumulator = []
2949-
for char in lines[-1]:
2950-
if char not in WSP:
2951-
break
2952-
whitespace_accumulator.append(char)
2953-
leading_whitespace = ''.join(whitespace_accumulator)
2950+
last_word_is_ew = (last_word_is_ew
2951+
and not bool(lines[-1].strip(_WSP)))
29542952
last_ew = None
29552953
continue
29562954
if not hasattr(part, 'encode'):
@@ -2990,10 +2988,11 @@ def _refold_parse_tree(parse_tree, *, policy):
29902988
else:
29912989
# We can't fold it onto the next line either...
29922990
lines[-1] += tstr
2991+
last_word_is_ew = last_word_is_ew and not bool(tstr.strip(_WSP))
29932992

29942993
return policy.linesep.join(lines) + policy.linesep
29952994

2996-
def _fold_as_ew(to_encode, lines, maxlen, last_ew, ew_combine_allowed, charset, leading_whitespace):
2995+
def _fold_as_ew(to_encode, lines, maxlen, last_ew, ew_combine_allowed, charset, last_word_is_ew):
29972996
"""Fold string to_encode into lines as encoded word, combining if allowed.
29982997
Return the new value for last_ew, or None if ew_combine_allowed is False.
29992998
@@ -3008,6 +3007,16 @@ def _fold_as_ew(to_encode, lines, maxlen, last_ew, ew_combine_allowed, charset,
30083007
to_encode = str(
30093008
get_unstructured(lines[-1][last_ew:] + to_encode))
30103009
lines[-1] = lines[-1][:last_ew]
3010+
elif last_word_is_ew:
3011+
# If we are following up an encoded word with another encoded word,
3012+
# any white space between the two will be ignored when decoded.
3013+
# Therefore, we encode all to-be-displayed whitespace in the second
3014+
# encoded word.
3015+
len_without_wsp = len(lines[-1].rstrip(_WSP))
3016+
leading_whitespace = lines[-1][len_without_wsp:]
3017+
lines[-1] = (lines[-1][:len_without_wsp]
3018+
+ (' ' if leading_whitespace else ''))
3019+
to_encode = leading_whitespace + to_encode
30113020
elif to_encode[0] in WSP:
30123021
# We're joining this to non-encoded text, so don't encode
30133022
# the leading blank.
@@ -3036,20 +3045,13 @@ def _fold_as_ew(to_encode, lines, maxlen, last_ew, ew_combine_allowed, charset,
30363045

30373046
while to_encode:
30383047
remaining_space = maxlen - len(lines[-1])
3039-
text_space = remaining_space - chrome_len - len(leading_whitespace)
3048+
text_space = remaining_space - chrome_len
30403049
if text_space <= 0:
3041-
lines.append(' ')
3050+
newline = _steal_trailing_WSP_if_exists(lines)
3051+
lines.append(newline or ' ')
3052+
new_last_ew = len(lines[-1])
30423053
continue
30433054

3044-
# If we are at the start of a continuation line, prepend whitespace
3045-
# (we only want to do this when the line starts with an encoded word
3046-
# but if we're folding in this helper function, then we know that we
3047-
# are going to be writing out an encoded word.)
3048-
if len(lines) > 1 and len(lines[-1]) == 1 and leading_whitespace:
3049-
encoded_word = _ew.encode(leading_whitespace, charset=encode_as)
3050-
lines[-1] += encoded_word
3051-
leading_whitespace = ''
3052-
30533055
to_encode_word = to_encode[:text_space]
30543056
encoded_word = _ew.encode(to_encode_word, charset=encode_as)
30553057
excess = len(encoded_word) - remaining_space
@@ -3061,7 +3063,6 @@ def _fold_as_ew(to_encode, lines, maxlen, last_ew, ew_combine_allowed, charset,
30613063
excess = len(encoded_word) - remaining_space
30623064
lines[-1] += encoded_word
30633065
to_encode = to_encode[len(to_encode_word):]
3064-
leading_whitespace = ''
30653066

30663067
if to_encode:
30673068
lines.append(' ')

Lib/inspect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2745,11 +2745,12 @@ class Parameter:
27452745
The annotation for the parameter if specified. If the
27462746
parameter has no annotation, this attribute is set to
27472747
`Parameter.empty`.
2748-
* kind : str
2748+
* kind
27492749
Describes how argument values are bound to the parameter.
27502750
Possible values: `Parameter.POSITIONAL_ONLY`,
27512751
`Parameter.POSITIONAL_OR_KEYWORD`, `Parameter.VAR_POSITIONAL`,
27522752
`Parameter.KEYWORD_ONLY`, `Parameter.VAR_KEYWORD`.
2753+
Every value has a `description` attribute describing meaning.
27532754
"""
27542755

27552756
__slots__ = ('_name', '_kind', '_default', '_annotation')

0 commit comments

Comments
 (0)