Skip to content

Commit 0d7fa54

Browse files
authored
Merge branch 'python:main' into t11
2 parents 24a0095 + 228c92e commit 0d7fa54

File tree

111 files changed

+2141
-1614
lines changed

Some content is hidden

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

111 files changed

+2141
-1614
lines changed

Diff for: Doc/howto/enum.rst

+2
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

@@ -712,6 +713,7 @@ It is also possible to name the combinations::
712713
... W = 2
713714
... X = 1
714715
... RWX = 7
716+
...
715717
>>> Perm.RWX
716718
<Perm.RWX: 7>
717719
>>> ~Perm.RWX

Diff for: 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'])

Diff for: 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

Diff for: Doc/library/collections.rst

+2
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

Diff for: Doc/library/datetime.rst

+1
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)

Diff for: Doc/library/decimal.rst

+1
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

Diff for: Doc/library/doctest.rst

+2
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ The fine print:
351351

352352
>>> def f(x):
353353
... r'''Backslashes in a raw docstring: m\n'''
354+
...
354355
>>> print(f.__doc__)
355356
Backslashes in a raw docstring: m\n
356357

@@ -360,6 +361,7 @@ The fine print:
360361

361362
>>> def f(x):
362363
... '''Backslashes in a raw docstring: m\\n'''
364+
...
363365
>>> print(f.__doc__)
364366
Backslashes in a raw docstring: m\n
365367

Diff for: Doc/library/email.policy.rst

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ file on disk and pass it to the system ``sendmail`` program on a Unix system:
9797
>>> from subprocess import Popen, PIPE
9898
>>> with open('mymsg.txt', 'rb') as f:
9999
... msg = message_from_binary_file(f, policy=policy.default)
100+
...
100101
>>> p = Popen(['sendmail', msg['To'].addresses[0]], stdin=PIPE)
101102
>>> g = BytesGenerator(p.stdin, policy=msg.policy.clone(linesep='\r\n'))
102103
>>> g.flatten(msg)

Diff for: Doc/library/enum.rst

+13
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ Data Types
292292
... @classmethod
293293
... def today(cls):
294294
... print('today is %s' % cls(date.today().isoweekday()).name)
295+
...
295296
>>> dir(Weekday.SATURDAY)
296297
['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']
297298

@@ -312,6 +313,7 @@ Data Types
312313
... return (count + 1) * 3
313314
... FIRST = auto()
314315
... SECOND = auto()
316+
...
315317
>>> PowersOfThree.SECOND.value
316318
6
317319

@@ -336,6 +338,7 @@ Data Types
336338
... if member.value == value:
337339
... return member
338340
... return None
341+
...
339342
>>> Build.DEBUG.value
340343
'debug'
341344
>>> Build('deBUG')
@@ -353,6 +356,7 @@ Data Types
353356
... def __repr__(self):
354357
... cls_name = self.__class__.__name__
355358
... return f'{cls_name}.{self.name}'
359+
...
356360
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
357361
(OtherStyle.ALTERNATE, 'OtherStyle.ALTERNATE', 'OtherStyle.ALTERNATE')
358362

@@ -367,6 +371,7 @@ Data Types
367371
... SOMETHING_ELSE = auto()
368372
... def __str__(self):
369373
... return f'{self.name}'
374+
...
370375
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
371376
(<OtherStyle.ALTERNATE: 1>, 'ALTERNATE', 'ALTERNATE')
372377

@@ -381,6 +386,7 @@ Data Types
381386
... SOMETHING_ELSE = auto()
382387
... def __format__(self, spec):
383388
... return f'{self.name}'
389+
...
384390
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
385391
(<OtherStyle.ALTERNATE: 1>, 'OtherStyle.ALTERNATE', 'ALTERNATE')
386392

@@ -403,6 +409,7 @@ Data Types
403409
... ONE = 1
404410
... TWO = 2
405411
... THREE = 3
412+
...
406413
>>> Numbers.THREE
407414
<Numbers.THREE: 3>
408415
>>> Numbers.ONE + Numbers.TWO
@@ -463,6 +470,7 @@ Data Types
463470
... RED = auto()
464471
... GREEN = auto()
465472
... BLUE = auto()
473+
...
466474
>>> purple = Color.RED | Color.BLUE
467475
>>> white = Color.RED | Color.GREEN | Color.BLUE
468476
>>> Color.GREEN in purple
@@ -570,6 +578,7 @@ Data Types
570578
... RED = auto()
571579
... GREEN = auto()
572580
... BLUE = auto()
581+
...
573582
>>> Color.RED & 2
574583
<Color: 0>
575584
>>> Color.RED | 2
@@ -695,6 +704,7 @@ Data Types
695704
... RED = auto()
696705
... GREEN = auto()
697706
... BLUE = auto()
707+
...
698708
>>> StrictFlag(2**2 + 2**4)
699709
Traceback (most recent call last):
700710
...
@@ -712,6 +722,7 @@ Data Types
712722
... RED = auto()
713723
... GREEN = auto()
714724
... BLUE = auto()
725+
...
715726
>>> ConformFlag(2**2 + 2**4)
716727
<ConformFlag.BLUE: 4>
717728

@@ -725,6 +736,7 @@ Data Types
725736
... RED = auto()
726737
... GREEN = auto()
727738
... BLUE = auto()
739+
...
728740
>>> EjectFlag(2**2 + 2**4)
729741
20
730742

@@ -738,6 +750,7 @@ Data Types
738750
... RED = auto()
739751
... GREEN = auto()
740752
... BLUE = auto()
753+
...
741754
>>> KeepFlag(2**2 + 2**4)
742755
<KeepFlag.BLUE|16: 20>
743756

Diff for: Doc/library/functions.rst

+1
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ are always available. They are listed here in alphabetical order.
462462
>>> class Shape:
463463
... def __dir__(self):
464464
... return ['area', 'perimeter', 'location']
465+
...
465466
>>> s = Shape()
466467
>>> dir(s)
467468
['area', 'location', 'perimeter']

Diff for: Doc/library/hashlib.rst

+1
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ update the hash:
497497
>>> h = blake2b()
498498
>>> for item in items:
499499
... h.update(item)
500+
...
500501
>>> h.hexdigest()
501502
'6ff843ba685842aa82031d3f53c48b66326df7639a63d128974c5c14f31a0f33343a8c65551134ed1ae0f2b0dd2bb495dc81039e3eeb0aa1bb0388bbeac29183'
502503

Diff for: Doc/library/inspect.rst

+2
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ function.
715715

716716
>>> def test(a, b):
717717
... pass
718+
...
718719
>>> sig = signature(test)
719720
>>> new_sig = sig.replace(return_annotation="new return anno")
720721
>>> str(new_sig)
@@ -1054,6 +1055,7 @@ Classes and functions
10541055
>>> from inspect import getcallargs
10551056
>>> def f(a, b=1, *pos, **named):
10561057
... pass
1058+
...
10571059
>>> getcallargs(f, 1, 2, 3) == {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)}
10581060
True
10591061
>>> getcallargs(f, a=2, x=4) == {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()}

Diff for: Doc/library/itertools.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Iterator Arguments Results
5252
Iterator Arguments Results Example
5353
============================ ============================ ================================================= =============================================================
5454
:func:`accumulate` p [,func] p0, p0+p1, p0+p1+p2, ... ``accumulate([1,2,3,4,5]) --> 1 3 6 10 15``
55-
:func:`batched` p, n [p0, p1, ..., p_n-1], ... ``batched('ABCDEFG', n=3) --> ABC DEF G``
55+
:func:`batched` p, n (p0, p1, ..., p_n-1), ... ``batched('ABCDEFG', n=3) --> ABC DEF G``
5656
:func:`chain` p, q, ... p0, p1, ... plast, q0, q1, ... ``chain('ABC', 'DEF') --> A B C D E F``
5757
:func:`chain.from_iterable` iterable p0, p1, ... plast, q0, q1, ... ``chain.from_iterable(['ABC', 'DEF']) --> A B C D E F``
5858
:func:`compress` data, selectors (d[0] if s[0]), (d[1] if s[1]), ... ``compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F``
@@ -166,11 +166,11 @@ loops that truncate the stream.
166166

167167
.. function:: batched(iterable, n)
168168

169-
Batch data from the *iterable* into lists of length *n*. The last
169+
Batch data from the *iterable* into tuples of length *n*. The last
170170
batch may be shorter than *n*.
171171

172-
Loops over the input iterable and accumulates data into lists up to
173-
size *n*. The input is consumed lazily, just enough to fill a list.
172+
Loops over the input iterable and accumulates data into tuples up to
173+
size *n*. The input is consumed lazily, just enough to fill a batch.
174174
The result is yielded as soon as the batch is full or when the input
175175
iterable is exhausted:
176176

@@ -179,14 +179,14 @@ loops that truncate the stream.
179179
>>> flattened_data = ['roses', 'red', 'violets', 'blue', 'sugar', 'sweet']
180180
>>> unflattened = list(batched(flattened_data, 2))
181181
>>> unflattened
182-
[['roses', 'red'], ['violets', 'blue'], ['sugar', 'sweet']]
182+
[('roses', 'red'), ('violets', 'blue'), ('sugar', 'sweet')]
183183

184184
>>> for batch in batched('ABCDEFG', 3):
185185
... print(batch)
186186
...
187-
['A', 'B', 'C']
188-
['D', 'E', 'F']
189-
['G']
187+
('A', 'B', 'C')
188+
('D', 'E', 'F')
189+
('G',)
190190

191191
Roughly equivalent to::
192192

@@ -195,7 +195,7 @@ loops that truncate the stream.
195195
if n < 1:
196196
raise ValueError('n must be at least one')
197197
it = iter(iterable)
198-
while (batch := list(islice(it, n))):
198+
while (batch := tuple(islice(it, n))):
199199
yield batch
200200

201201
.. versionadded:: 3.12

Diff for: Doc/library/re.rst

+2
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ Functions
973973
>>> def dashrepl(matchobj):
974974
... if matchobj.group(0) == '-': return ' '
975975
... else: return '-'
976+
...
976977
>>> re.sub('-{1,2}', dashrepl, 'pro----gram-files')
977978
'pro--gram files'
978979
>>> re.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=re.IGNORECASE)
@@ -1672,6 +1673,7 @@ in each word of a sentence except for the first and last characters::
16721673
... inner_word = list(m.group(2))
16731674
... random.shuffle(inner_word)
16741675
... return m.group(1) + "".join(inner_word) + m.group(3)
1676+
...
16751677
>>> text = "Professor Abdolmalek, please report your absences promptly."
16761678
>>> re.sub(r"(\w)(\w+)(\w)", repl, text)
16771679
'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'

Diff for: Doc/library/socket.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,14 @@ Constants
428428
.. versionchanged:: 3.12
429429
Added ``SO_RTABLE`` and ``SO_USER_COOKIE``. On OpenBSD
430430
and FreeBSD respectively those constants can be used in the same way that
431-
``SO_MARK`` is used on Linux.
431+
``SO_MARK`` is used on Linux. Also added missing TCP socket options from
432+
Linux: ``TCP_MD5SIG``, ``TCP_THIN_LINEAR_TIMEOUTS``, ``TCP_THIN_DUPACK``,
433+
``TCP_REPAIR``, ``TCP_REPAIR_QUEUE``, ``TCP_QUEUE_SEQ``,
434+
``TCP_REPAIR_OPTIONS``, ``TCP_TIMESTAMP``, ``TCP_CC_INFO``,
435+
``TCP_SAVE_SYN``, ``TCP_SAVED_SYN``, ``TCP_REPAIR_WINDOW``,
436+
``TCP_FASTOPEN_CONNECT``, ``TCP_ULP``, ``TCP_MD5SIG_EXT``,
437+
``TCP_FASTOPEN_KEY``, ``TCP_FASTOPEN_NO_COOKIE``,
438+
``TCP_ZEROCOPY_RECEIVE``, ``TCP_INQ``, ``TCP_TX_DELAY``.
432439

433440
.. data:: AF_CAN
434441
PF_CAN

Diff for: Doc/library/sqlite3.rst

+11-6
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ Module functions
397397
>>> con = sqlite3.connect(":memory:")
398398
>>> def evil_trace(stmt):
399399
... 5/0
400+
...
400401
>>> con.set_trace_callback(evil_trace)
401402
>>> def debug(unraisable):
402403
... print(f"{unraisable.exc_value!r} in callback {unraisable.object.__name__}")
@@ -1929,12 +1930,16 @@ How to use placeholders to bind values in SQL queries
19291930

19301931
SQL operations usually need to use values from Python variables. However,
19311932
beware of using Python's string operations to assemble queries, as they
1932-
are vulnerable to `SQL injection attacks`_ (see the `xkcd webcomic
1933-
<https://xkcd.com/327/>`_ for a humorous example of what can go wrong)::
1934-
1935-
# Never do this -- insecure!
1936-
symbol = 'RHAT'
1937-
cur.execute("SELECT * FROM stocks WHERE symbol = '%s'" % symbol)
1933+
are vulnerable to `SQL injection attacks`_. For example, an attacker can simply
1934+
close the single quote and inject ``OR TRUE`` to select all rows::
1935+
1936+
>>> # Never do this -- insecure!
1937+
>>> symbol = input()
1938+
' OR TRUE; --
1939+
>>> sql = "SELECT * FROM stocks WHERE symbol = '%s'" % symbol
1940+
>>> print(sql)
1941+
SELECT * FROM stocks WHERE symbol = '' OR TRUE; --'
1942+
>>> cur.execute(sql)
19381943

19391944
Instead, use the DB-API's parameter substitution. To insert a variable into a
19401945
query string, use a placeholder in the string, and substitute the actual values

Diff for: Doc/library/statistics.rst

+1
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ probability that the Python room will stay within its capacity limits?
996996
>>> seed(8675309)
997997
>>> def trial():
998998
... return choices(('Python', 'Ruby'), (p, q), k=n).count('Python')
999+
...
9991000
>>> mean(trial() <= k for i in range(10_000))
10001001
0.8398
10011002

Diff for: Doc/library/stdtypes.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -4459,6 +4459,7 @@ can be used interchangeably to index the same dictionary entry.
44594459
>>> class Counter(dict):
44604460
... def __missing__(self, key):
44614461
... return 0
4462+
...
44624463
>>> c = Counter()
44634464
>>> c['red']
44644465
0
@@ -4716,6 +4717,7 @@ An example of dictionary view usage::
47164717
>>> n = 0
47174718
>>> for val in values:
47184719
... n += val
4720+
...
47194721
>>> print(n)
47204722
504
47214723

@@ -4741,7 +4743,7 @@ An example of dictionary view usage::
47414743

47424744
>>> # get back a read-only proxy for the original dictionary
47434745
>>> values.mapping
4744-
mappingproxy({'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500})
4746+
mappingproxy({'bacon': 1, 'spam': 500})
47454747
>>> values.mapping['spam']
47464748
500
47474749

Diff for: Doc/library/unittest.mock.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,7 @@ decorator:
16041604
>>> @patch.dict(foo, {'newkey': 'newvalue'})
16051605
... def test():
16061606
... assert foo == {'newkey': 'newvalue'}
1607+
...
16071608
>>> test()
16081609
>>> assert foo == {}
16091610

Diff for: Doc/library/xml.etree.elementtree.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ Example of changing the attribute "target" of every link in first paragraph::
12121212
[<Element 'a' at 0xb77ec2ac>, <Element 'a' at 0xb77ec1cc>]
12131213
>>> for i in links: # Iterates through all found links
12141214
... i.attrib["target"] = "blank"
1215+
...
12151216
>>> tree.write("output.xhtml")
12161217

12171218
.. _elementtree-qname-objects:

Diff for: Doc/library/zipfile.rst

+1
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ The :class:`PyZipFile` constructor takes the same parameters as the
672672
>>> def notests(s):
673673
... fn = os.path.basename(s)
674674
... return (not (fn == 'test' or fn.startswith('test_')))
675+
...
675676
>>> zf.writepy('myprog', filterfunc=notests)
676677

677678
The :meth:`writepy` method makes archives with file names like

0 commit comments

Comments
 (0)