Skip to content

Commit

Permalink
Merge branch 'python:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
YvesDup authored Jan 26, 2023
2 parents 282437e + 9f2c479 commit a23c8b8
Show file tree
Hide file tree
Showing 199 changed files with 7,143 additions and 3,224 deletions.
8 changes: 4 additions & 4 deletions .azure-pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
displayName: Pre-build checks

pool:
vmImage: ubuntu-20.04
vmImage: ubuntu-22.04

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

pool:
vmImage: ubuntu-20.04
vmImage: ubuntu-22.04

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

pool:
vmImage: ubuntu-20.04
vmImage: ubuntu-22.04

variables:
testRunTitle: '$(build.sourceBranchName)-linux'
Expand All @@ -78,7 +78,7 @@ jobs:
)
pool:
vmImage: ubuntu-20.04
vmImage: ubuntu-22.04

variables:
testRunTitle: '$(Build.SourceBranchName)-linux-coverage'
Expand Down
8 changes: 4 additions & 4 deletions .azure-pipelines/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
displayName: Pre-build checks

pool:
vmImage: ubuntu-20.04
vmImage: ubuntu-22.04

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

pool:
vmImage: ubuntu-20.04
vmImage: ubuntu-22.04

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

pool:
vmImage: ubuntu-20.04
vmImage: ubuntu-22.04

variables:
testRunTitle: '$(system.pullRequest.TargetBranch)-linux'
Expand All @@ -78,7 +78,7 @@ jobs:
)
pool:
vmImage: ubuntu-20.04
vmImage: ubuntu-22.04

variables:
testRunTitle: '$(Build.SourceBranchName)-linux-coverage'
Expand Down
2 changes: 1 addition & 1 deletion .azure-pipelines/windows-layout-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps:
displayName: Show layout info (${{ parameters.kind }})

- ${{ if eq(parameters.fulltest, 'true') }}:
- script: .\python.exe -m test -q -uall -u-cpu -rwW --slowest --timeout=1200 -j0 --junit-xml="$(Build.BinariesDirectory)\test-results-${{ parameters.kind }}.xml" --tempdir "$(Build.BinariesDirectory)\tmp-${{ parameters.kind }}-$(arch)"
- script: .\python.exe -m test -q -uall -u-cpu -rwW --slowest --timeout=1200 -j0 --junit-xml="$(Build.BinariesDirectory)\test-results-${{ parameters.kind }}.xml" --tempdir "$(Build.BinariesDirectory)\tmp-${{ parameters.kind }}-$(arch)" -i test_launcher
workingDirectory: $(Build.BinariesDirectory)\layout-${{ parameters.kind }}-$(arch)
displayName: ${{ parameters.kind }} Tests
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# GitHub
.github/** @ezio-melotti

# Build system
configure* @erlend-aasland @corona10

# asyncio
**/*asyncio* @1st1 @asvetlov @gvanrossum @kumaraditya303

Expand Down
4 changes: 4 additions & 0 deletions Doc/c-api/long.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
ignored. If there are no digits or *str* is not NULL-terminated following the
digits and trailing whitespace, :exc:`ValueError` will be raised.
.. seealso:: Python methods :meth:`int.to_bytes` and :meth:`int.from_bytes`
to convert a :c:type:`PyLongObject` to/from an array of bytes in base
``256``. You can call those from C using :c:func:`PyObject_CallMethod`.
.. c:function:: PyObject* PyLong_FromUnicodeObject(PyObject *u, int base)
Expand Down
41 changes: 31 additions & 10 deletions Doc/howto/logging-cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1982,26 +1982,47 @@ Using a rotator and namer to customize log rotation processing
--------------------------------------------------------------

An example of how you can define a namer and rotator is given in the following
snippet, which shows zlib-based compression of the log file::
runnable script, which shows gzip compression of the log file::

import gzip
import logging
import logging.handlers
import os
import shutil

def namer(name):
return name + ".gz"

def rotator(source, dest):
with open(source, "rb") as sf:
data = sf.read()
compressed = zlib.compress(data, 9)
with open(dest, "wb") as df:
df.write(compressed)
with open(source, 'rb') as f_in:
with gzip.open(dest, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
os.remove(source)

rh = logging.handlers.RotatingFileHandler(...)

rh = logging.handlers.RotatingFileHandler('rotated.log', maxBytes=128, backupCount=5)
rh.rotator = rotator
rh.namer = namer

These are not "true" .gz files, as they are bare compressed data, with no
"container" such as you’d find in an actual gzip file. This snippet is just
for illustration purposes.
root = logging.getLogger()
root.setLevel(logging.INFO)
root.addHandler(rh)
f = logging.Formatter('%(asctime)s %(message)s')
rh.setFormatter(f)
for i in range(1000):
root.info(f'Message no. {i + 1}')

After running this, you will see six new files, five of which are compressed:

.. code-block:: shell-session
$ ls rotated.log*
rotated.log rotated.log.2.gz rotated.log.4.gz
rotated.log.1.gz rotated.log.3.gz rotated.log.5.gz
$ zcat rotated.log.1.gz
2023-01-20 02:28:17,767 Message no. 996
2023-01-20 02:28:17,767 Message no. 997
2023-01-20 02:28:17,767 Message no. 998
A more elaborate multiprocessing example
----------------------------------------
Expand Down
10 changes: 4 additions & 6 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ an event loop:
running event loop.

If there is no running event loop set, the function will return
the result of calling ``get_event_loop_policy().get_event_loop()``.
the result of the ``get_event_loop_policy().get_event_loop()`` call.

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

.. note::
In Python versions 3.10.0--3.10.8 and 3.11.0 this function
(and other functions which used it implicitly) emitted a
:exc:`DeprecationWarning` if there was no running event loop, even if
the current loop was set.
.. deprecated:: 3.12
Deprecation warning is emitted if there is no current event loop.
In some future Python release this will become an error.

.. function:: set_event_loop(loop)

Expand Down
8 changes: 5 additions & 3 deletions Doc/library/asyncio-policy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ asyncio ships with the following built-in policies:

On Windows, :class:`ProactorEventLoop` is now used by default.

.. versionchanged:: 3.12
:meth:`get_event_loop` now raises a :exc:`RuntimeError` if there is no
current event loop set.
.. deprecated:: 3.12
The :meth:`get_event_loop` method of the default asyncio policy now emits
a :exc:`DeprecationWarning` if there is no current event loop set and it
decides to create one.
In some future Python release this will become an error.


.. class:: WindowsSelectorEventLoopPolicy
Expand Down
12 changes: 12 additions & 0 deletions Doc/library/asyncio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ Additionally, there are **low-level** APIs for
* :ref:`bridge <asyncio-futures>` callback-based libraries and code
with async/await syntax.

You can experiment with an ``asyncio`` concurrent context in the REPL:

.. code-block:: pycon
$ python -m asyncio
asyncio REPL ...
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> await asyncio.sleep(10, result='hello')
'hello'
.. include:: ../includes/wasm-notavail.rst

.. We use the "rubric" directive here to avoid creating
Expand Down
21 changes: 15 additions & 6 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,14 @@ integer, string, bytes, a :mod:`ctypes` instance, or an object with an
Return types
^^^^^^^^^^^^

.. testsetup::

from ctypes import CDLL, c_char, c_char_p
from ctypes.util import find_library
libc = CDLL(find_library('c'))
strchr = libc.strchr


By default functions are assumed to return the C :c:expr:`int` type. Other
return types can be specified by setting the :attr:`restype` attribute of the
function object.
Expand Down Expand Up @@ -502,18 +510,19 @@ If you want to avoid the ``ord("x")`` calls above, you can set the
:attr:`argtypes` attribute, and the second argument will be converted from a
single character Python bytes object into a C char::

.. doctest::

>>> strchr.restype = c_char_p
>>> strchr.argtypes = [c_char_p, c_char]
>>> strchr(b"abcdef", b"d")
'def'
b'def'
>>> strchr(b"abcdef", b"def")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ArgumentError: argument 2: TypeError: one character string expected
ctypes.ArgumentError: argument 2: TypeError: one character bytes, bytearray or integer expected
>>> print(strchr(b"abcdef", b"x"))
None
>>> strchr(b"abcdef", b"d")
'def'
b'def'
>>>

You can also use a callable Python object (a function or a class for example) as
Expand Down Expand Up @@ -1656,12 +1665,12 @@ They are instances of a private class:
passed arguments.


.. audit-event:: ctypes.seh_exception code foreign-functions
.. audit-event:: ctypes.set_exception code foreign-functions

On Windows, when a foreign function call raises a system exception (for
example, due to an access violation), it will be captured and replaced with
a suitable Python exception. Further, an auditing event
``ctypes.seh_exception`` with argument ``code`` will be raised, allowing an
``ctypes.set_exception`` with argument ``code`` will be raised, allowing an
audit hook to replace the exception with its own.

.. audit-event:: ctypes.call_function func_pointer,arguments foreign-functions
Expand Down
9 changes: 4 additions & 5 deletions Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -982,12 +982,11 @@ Other constructors, all class methods:
are equal to the given :class:`.time` object's. If the *tzinfo*
argument is provided, its value is used to set the :attr:`.tzinfo` attribute
of the result, otherwise the :attr:`~.time.tzinfo` attribute of the *time* argument
is used.
is used. If the *date* argument is a :class:`.datetime` object, its time components
and :attr:`.tzinfo` attributes are ignored.

For any :class:`.datetime` object *d*,
``d == datetime.combine(d.date(), d.time(), d.tzinfo)``. If date is a
:class:`.datetime` object, its time components and :attr:`.tzinfo` attributes
are ignored.
``d == datetime.combine(d.date(), d.time(), d.tzinfo)``.

.. versionchanged:: 3.6
Added the *tzinfo* argument.
Expand Down Expand Up @@ -1351,7 +1350,7 @@ Instance methods:

Because naive ``datetime`` objects are treated by many ``datetime`` methods
as local times, it is preferred to use aware datetimes to represent times
in UTC; as a result, using ``utcfromtimetuple`` may give misleading
in UTC; as a result, using :meth:`datetime.utctimetuple` may give misleading
results. If you have a naive ``datetime`` representing UTC, use
``datetime.replace(tzinfo=timezone.utc)`` to make it aware, at which point
you can use :meth:`.datetime.timetuple`.
Expand Down
Loading

0 comments on commit a23c8b8

Please sign in to comment.