Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6f4701b

Browse filesBrowse files
authored
Merge branch 'python:main' into buffered-gzip-writes
2 parents 943ca9c + b53bad6 commit 6f4701b
Copy full SHA for 6f4701b

File tree

Expand file treeCollapse file tree

68 files changed

+1968
-933
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

68 files changed

+1968
-933
lines changed

‎.azure-pipelines/ci.yml

Copy file name to clipboardExpand all lines: .azure-pipelines/ci.yml
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
displayName: Pre-build checks
99

1010
pool:
11-
vmImage: ubuntu-20.04
11+
vmImage: ubuntu-22.04
1212

1313
steps:
1414
- template: ./prebuild-checks.yml
@@ -20,7 +20,7 @@ jobs:
2020
condition: and(succeeded(), eq(dependencies.Prebuild.outputs['docs.run'], 'true'))
2121

2222
pool:
23-
vmImage: ubuntu-20.04
23+
vmImage: ubuntu-22.04
2424

2525
steps:
2626
- template: ./docs-steps.yml
@@ -52,7 +52,7 @@ jobs:
5252
condition: and(succeeded(), eq(dependencies.Prebuild.outputs['tests.run'], 'true'))
5353

5454
pool:
55-
vmImage: ubuntu-20.04
55+
vmImage: ubuntu-22.04
5656

5757
variables:
5858
testRunTitle: '$(build.sourceBranchName)-linux'
@@ -78,7 +78,7 @@ jobs:
7878
)
7979
8080
pool:
81-
vmImage: ubuntu-20.04
81+
vmImage: ubuntu-22.04
8282

8383
variables:
8484
testRunTitle: '$(Build.SourceBranchName)-linux-coverage'

‎.azure-pipelines/pr.yml

Copy file name to clipboardExpand all lines: .azure-pipelines/pr.yml
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
displayName: Pre-build checks
99

1010
pool:
11-
vmImage: ubuntu-20.04
11+
vmImage: ubuntu-22.04
1212

1313
steps:
1414
- template: ./prebuild-checks.yml
@@ -20,7 +20,7 @@ jobs:
2020
condition: and(succeeded(), eq(dependencies.Prebuild.outputs['docs.run'], 'true'))
2121

2222
pool:
23-
vmImage: ubuntu-20.04
23+
vmImage: ubuntu-22.04
2424

2525
steps:
2626
- template: ./docs-steps.yml
@@ -52,7 +52,7 @@ jobs:
5252
condition: and(succeeded(), eq(dependencies.Prebuild.outputs['tests.run'], 'true'))
5353

5454
pool:
55-
vmImage: ubuntu-20.04
55+
vmImage: ubuntu-22.04
5656

5757
variables:
5858
testRunTitle: '$(system.pullRequest.TargetBranch)-linux'
@@ -78,7 +78,7 @@ jobs:
7878
)
7979
8080
pool:
81-
vmImage: ubuntu-20.04
81+
vmImage: ubuntu-22.04
8282

8383
variables:
8484
testRunTitle: '$(Build.SourceBranchName)-linux-coverage'

‎Doc/howto/logging-cookbook.rst

Copy file name to clipboardExpand all lines: Doc/howto/logging-cookbook.rst
+31-10Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,26 +1982,47 @@ Using a rotator and namer to customize log rotation processing
19821982
--------------------------------------------------------------
19831983

19841984
An example of how you can define a namer and rotator is given in the following
1985-
snippet, which shows zlib-based compression of the log file::
1985+
runnable script, which shows gzip compression of the log file::
1986+
1987+
import gzip
1988+
import logging
1989+
import logging.handlers
1990+
import os
1991+
import shutil
19861992

19871993
def namer(name):
19881994
return name + ".gz"
19891995

19901996
def rotator(source, dest):
1991-
with open(source, "rb") as sf:
1992-
data = sf.read()
1993-
compressed = zlib.compress(data, 9)
1994-
with open(dest, "wb") as df:
1995-
df.write(compressed)
1997+
with open(source, 'rb') as f_in:
1998+
with gzip.open(dest, 'wb') as f_out:
1999+
shutil.copyfileobj(f_in, f_out)
19962000
os.remove(source)
19972001

1998-
rh = logging.handlers.RotatingFileHandler(...)
2002+
2003+
rh = logging.handlers.RotatingFileHandler('rotated.log', maxBytes=128, backupCount=5)
19992004
rh.rotator = rotator
20002005
rh.namer = namer
20012006

2002-
These are not "true" .gz files, as they are bare compressed data, with no
2003-
"container" such as you’d find in an actual gzip file. This snippet is just
2004-
for illustration purposes.
2007+
root = logging.getLogger()
2008+
root.setLevel(logging.INFO)
2009+
root.addHandler(rh)
2010+
f = logging.Formatter('%(asctime)s %(message)s')
2011+
rh.setFormatter(f)
2012+
for i in range(1000):
2013+
root.info(f'Message no. {i + 1}')
2014+
2015+
After running this, you will see six new files, five of which are compressed:
2016+
2017+
.. code-block:: shell-session
2018+
2019+
$ ls rotated.log*
2020+
rotated.log rotated.log.2.gz rotated.log.4.gz
2021+
rotated.log.1.gz rotated.log.3.gz rotated.log.5.gz
2022+
$ zcat rotated.log.1.gz
2023+
2023-01-20 02:28:17,767 Message no. 996
2024+
2023-01-20 02:28:17,767 Message no. 997
2025+
2023-01-20 02:28:17,767 Message no. 998
20052026
20062027
A more elaborate multiprocessing example
20072028
----------------------------------------

‎Doc/library/ctypes.rst

Copy file name to clipboardExpand all lines: Doc/library/ctypes.rst
+13-4Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,14 @@ integer, string, bytes, a :mod:`ctypes` instance, or an object with an
466466
Return types
467467
^^^^^^^^^^^^
468468

469+
.. testsetup::
470+
471+
from ctypes import CDLL, c_char, c_char_p
472+
from ctypes.util import find_library
473+
libc = CDLL(find_library('c'))
474+
strchr = libc.strchr
475+
476+
469477
By default functions are assumed to return the C :c:expr:`int` type. Other
470478
return types can be specified by setting the :attr:`restype` attribute of the
471479
function object.
@@ -502,18 +510,19 @@ If you want to avoid the ``ord("x")`` calls above, you can set the
502510
:attr:`argtypes` attribute, and the second argument will be converted from a
503511
single character Python bytes object into a C char::
504512

513+
.. doctest::
514+
505515
>>> strchr.restype = c_char_p
506516
>>> strchr.argtypes = [c_char_p, c_char]
507517
>>> strchr(b"abcdef", b"d")
508-
'def'
518+
b'def'
509519
>>> strchr(b"abcdef", b"def")
510520
Traceback (most recent call last):
511-
File "<stdin>", line 1, in <module>
512-
ArgumentError: argument 2: TypeError: one character string expected
521+
ctypes.ArgumentError: argument 2: TypeError: one character bytes, bytearray or integer expected
513522
>>> print(strchr(b"abcdef", b"x"))
514523
None
515524
>>> strchr(b"abcdef", b"d")
516-
'def'
525+
b'def'
517526
>>>
518527

519528
You can also use a callable Python object (a function or a class for example) as

‎Doc/library/enum.rst

Copy file name to clipboardExpand all lines: Doc/library/enum.rst
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ are not normal Python classes. See
5252

5353
.. note:: Nomenclature
5454

55-
- The class :class:`Color` is an *enumeration* (or *enum*)
56-
- The attributes :attr:`Color.RED`, :attr:`Color.GREEN`, etc., are
55+
- The class :class:`!Color` is an *enumeration* (or *enum*)
56+
- The attributes :attr:`!Color.RED`, :attr:`!Color.GREEN`, etc., are
5757
*enumeration members* (or *members*) and are functionally constants.
5858
- The enum members have *names* and *values* (the name of
59-
:attr:`Color.RED` is ``RED``, the value of :attr:`Color.BLUE` is
59+
:attr:`!Color.RED` is ``RED``, the value of :attr:`!Color.BLUE` is
6060
``3``, etc.)
6161

6262
---------------
@@ -165,8 +165,8 @@ Data Types
165165
to subclass *EnumType* -- see :ref:`Subclassing EnumType <enumtype-examples>`
166166
for details.
167167

168-
*EnumType* is responsible for setting the correct :meth:`__repr__`,
169-
:meth:`__str__`, :meth:`__format__`, and :meth:`__reduce__` methods on the
168+
*EnumType* is responsible for setting the correct :meth:`!__repr__`,
169+
:meth:`!__str__`, :meth:`!__format__`, and :meth:`!__reduce__` methods on the
170170
final *enum*, as well as creating the enum members, properly handling
171171
duplicates, providing iteration over the enum class, etc.
172172

@@ -424,9 +424,9 @@ Data Types
424424
Using :class:`auto` with :class:`IntEnum` results in integers of increasing
425425
value, starting with ``1``.
426426

427-
.. versionchanged:: 3.11 :meth:`__str__` is now :func:`int.__str__` to
427+
.. versionchanged:: 3.11 :meth:`~object.__str__` is now :meth:`!int.__str__` to
428428
better support the *replacement of existing constants* use-case.
429-
:meth:`__format__` was already :func:`int.__format__` for that same reason.
429+
:meth:`~object.__format__` was already :meth:`!int.__format__` for that same reason.
430430

431431

432432
.. class:: StrEnum
@@ -761,11 +761,11 @@ Data Types
761761
Supported ``__dunder__`` names
762762
""""""""""""""""""""""""""""""
763763

764-
:attr:`__members__` is a read-only ordered mapping of ``member_name``:``member``
764+
:attr:`~EnumType.__members__` is a read-only ordered mapping of ``member_name``:``member``
765765
items. It is only available on the class.
766766

767-
:meth:`__new__`, if specified, must create and return the enum members; it is
768-
also a very good idea to set the member's :attr:`_value_` appropriately. Once
767+
:meth:`~object.__new__`, if specified, must create and return the enum members; it is
768+
also a very good idea to set the member's :attr:`!_value_` appropriately. Once
769769
all the members are created it is no longer used.
770770

771771

@@ -804,7 +804,7 @@ Utilities and Decorators
804804
.. class:: auto
805805

806806
*auto* can be used in place of a value. If used, the *Enum* machinery will
807-
call an *Enum*'s :meth:`_generate_next_value_` to get an appropriate value.
807+
call an *Enum*'s :meth:`~Enum._generate_next_value_` to get an appropriate value.
808808
For *Enum* and *IntEnum* that appropriate value will be the last value plus
809809
one; for *Flag* and *IntFlag* it will be the first power-of-two greater
810810
than the highest value; for *StrEnum* it will be the lower-cased version of
@@ -847,7 +847,7 @@ Utilities and Decorators
847847
.. decorator:: unique
848848

849849
A :keyword:`class` decorator specifically for enumerations. It searches an
850-
enumeration's :attr:`__members__`, gathering any aliases it finds; if any are
850+
enumeration's :attr:`~EnumType.__members__`, gathering any aliases it finds; if any are
851851
found :exc:`ValueError` is raised with the details::
852852

853853
>>> from enum import Enum, unique

‎Doc/library/io.rst

Copy file name to clipboardExpand all lines: Doc/library/io.rst
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,8 @@ Text I/O
10211021

10221022
.. versionadded:: 3.7
10231023

1024-
.. method:: reconfigure(*[, encoding][, errors][, newline][, \
1025-
line_buffering][, write_through])
1024+
.. method:: reconfigure(*, encoding=None, errors=None, newline=None, \
1025+
line_buffering=None, write_through=None)
10261026

10271027
Reconfigure this text stream using new settings for *encoding*,
10281028
*errors*, *newline*, *line_buffering* and *write_through*.

‎Doc/library/optparse.rst

Copy file name to clipboardExpand all lines: Doc/library/optparse.rst
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ Other actions
404404
Some other actions supported by :mod:`optparse` are:
405405

406406
``"store_const"``
407-
store a constant value
407+
store a constant value, pre-set via :attr:`Option.const`
408408

409409
``"append"``
410410
append this option's argument to a list
@@ -925,7 +925,7 @@ The canonical way to create an :class:`Option` instance is with the
925925
store this option's argument (default)
926926

927927
``"store_const"``
928-
store a constant value
928+
store a constant value, pre-set via :attr:`Option.const`
929929

930930
``"store_true"``
931931
store ``True``
@@ -937,7 +937,7 @@ The canonical way to create an :class:`Option` instance is with the
937937
append this option's argument to a list
938938

939939
``"append_const"``
940-
append a constant value to a list
940+
append a constant value to a list, pre-set via :attr:`Option.const`
941941

942942
``"count"``
943943
increment a counter by one

‎Doc/library/pathlib.rst

Copy file name to clipboardExpand all lines: Doc/library/pathlib.rst
+16-15Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ Accessing individual parts
266266
To access the individual "parts" (components) of a path, use the following
267267
property:
268268

269-
.. data:: PurePath.parts
269+
.. attribute:: PurePath.parts
270270

271271
A tuple giving access to the path's various components::
272272

@@ -290,7 +290,7 @@ Methods and properties
290290

291291
Pure paths provide the following methods and properties:
292292

293-
.. data:: PurePath.drive
293+
.. attribute:: PurePath.drive
294294

295295
A string representing the drive letter or name, if any::
296296

@@ -306,7 +306,7 @@ Pure paths provide the following methods and properties:
306306
>>> PureWindowsPath('//host/share/foo.txt').drive
307307
'\\\\host\\share'
308308

309-
.. data:: PurePath.root
309+
.. attribute:: PurePath.root
310310

311311
A string representing the (local or global) root, if any::
312312

@@ -342,7 +342,7 @@ Pure paths provide the following methods and properties:
342342
an implementation-defined manner, although more than two leading slashes
343343
shall be treated as a single slash."*
344344

345-
.. data:: PurePath.anchor
345+
.. attribute:: PurePath.anchor
346346

347347
The concatenation of the drive and root::
348348

@@ -356,7 +356,7 @@ Pure paths provide the following methods and properties:
356356
'\\\\host\\share\\'
357357

358358

359-
.. data:: PurePath.parents
359+
.. attribute:: PurePath.parents
360360

361361
An immutable sequence providing access to the logical ancestors of
362362
the path::
@@ -372,7 +372,7 @@ Pure paths provide the following methods and properties:
372372
.. versionchanged:: 3.10
373373
The parents sequence now supports :term:`slices <slice>` and negative index values.
374374

375-
.. data:: PurePath.parent
375+
.. attribute:: PurePath.parent
376376

377377
The logical parent of the path::
378378

@@ -401,7 +401,7 @@ Pure paths provide the following methods and properties:
401401
symlinks and eliminate ``".."`` components.
402402

403403

404-
.. data:: PurePath.name
404+
.. attribute:: PurePath.name
405405

406406
A string representing the final path component, excluding the drive and
407407
root, if any::
@@ -417,7 +417,7 @@ Pure paths provide the following methods and properties:
417417
''
418418

419419

420-
.. data:: PurePath.suffix
420+
.. attribute:: PurePath.suffix
421421

422422
The file extension of the final component, if any::
423423

@@ -429,7 +429,7 @@ Pure paths provide the following methods and properties:
429429
''
430430

431431

432-
.. data:: PurePath.suffixes
432+
.. attribute:: PurePath.suffixes
433433

434434
A list of the path's file extensions::
435435

@@ -441,7 +441,7 @@ Pure paths provide the following methods and properties:
441441
[]
442442

443443

444-
.. data:: PurePath.stem
444+
.. attribute:: PurePath.stem
445445

446446
The final path component, without its suffix::
447447

@@ -1270,7 +1270,8 @@ call fails (for example because the path doesn't exist).
12701270
.. method:: Path.rglob(pattern)
12711271

12721272
Glob the given relative *pattern* recursively. This is like calling
1273-
:func:`Path.glob` with "``**/``" added in front of the *pattern*::
1273+
:func:`Path.glob` with "``**/``" added in front of the *pattern*, where
1274+
*patterns* are the same as for :mod:`fnmatch`::
12741275

12751276
>>> sorted(Path().rglob("*.py"))
12761277
[PosixPath('build/lib/pathlib.py'),
@@ -1445,11 +1446,11 @@ Below is a table mapping various :mod:`os` functions to their corresponding
14451446
:meth:`Path.group`
14461447
:func:`os.path.isabs` :meth:`PurePath.is_absolute`
14471448
:func:`os.path.join` :func:`PurePath.joinpath`
1448-
:func:`os.path.basename` :data:`PurePath.name`
1449-
:func:`os.path.dirname` :data:`PurePath.parent`
1449+
:func:`os.path.basename` :attr:`PurePath.name`
1450+
:func:`os.path.dirname` :attr:`PurePath.parent`
14501451
:func:`os.path.samefile` :meth:`Path.samefile`
1451-
:func:`os.path.splitext` :data:`PurePath.stem` and
1452-
:data:`PurePath.suffix`
1452+
:func:`os.path.splitext` :attr:`PurePath.stem` and
1453+
:attr:`PurePath.suffix`
14531454
==================================== ==============================
14541455

14551456
.. rubric:: Footnotes

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.