8000 Merge branch 'main' into asyncio-runner · python/cpython@98e39db · GitHub
[go: up one dir, main page]

Skip to content

Commit 98e39db

Browse files
committed
Merge branch 'main' into asyncio-runner
2 parents 8014227 + 9523c0d commit 98e39db

File tree

88 files changed

+1870
-704
lines changed

Some content is hidden

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

88 files changed

+1870
-704
lines changed

Doc/c-api/float.rst

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,85 @@ Floating Point Objects
7676
.. c:function:: double PyFloat_GetMin()
7777
7878
Return the minimum normalized positive float *DBL_MIN* as C :c:type:`double`.
79+
80+
81+
Pack and Unpack functions
82+
=========================
83+
84+
The pack and unpack functions provide an efficient platform-independent way to
85+
store floating-point values as byte strings. The Pack routines produce a bytes
86+
string from a C :c:type:`double`, and the Unpack routines produce a C
87+
:c:type:`double` from such a bytes string. The suffix (2, 4 or 8) specifies the
88+
number of bytes in the bytes string.
89+
90+
On platforms that appear to use IEEE 754 formats these functions work by
91+
copying bits. On other platforms, the 2-byte format is identical to the IEEE
92+
754 binary16 half-precision format, the 4-byte format (32-bit) is identical to
93+
the IEEE 754 binary32 single precision format, and the 8-byte format to the
94+
IEEE 754 binary64 double precision format, although the packing of INFs and
95+
NaNs (if such things exist on the platform) isn't handled correctly, and
96+
attempting to unpack a bytes string containing an IEEE INF or NaN will raise an
97+
exception.
98+
99+
On non-IEEE platforms with more precision, or larger dynamic range, than IEEE
100+
754 supports, not all values can be packed; on non-IEEE platforms with less
101+
precision, or smaller dynamic range, not all values can be unpacked. What
102+
happens in such cases is partly accidental (alas).
103+
104+
.. versionadded:: 3.11
105+
106+
Pack functions
107+
--------------
108+
109+
The pack routines write 2, 4 or 8 bytes, starting at *p*. *le* is an
110+
:c:type:`int` argument, non-zero if you want the bytes string in little-endian
111+
format (exponent last, at ``p+1``, ``p+3``, or ``p+6`` ``p+7``), zero if you
112+
want big-endian format (exponent first, at *p*).
113+
114+
Return value: ``0`` if all is OK, ``-1`` if error (and an exception is set,
115+
most likely :exc:`OverflowError`).
116+
117+
There are two problems on non-IEEE platforms:
118+
119+
* What this does is undefined if *x* is a NaN or infinity.
120+
* ``-0.0`` and ``+0.0`` produce the same bytes string.
121+
122+
.. c:function:: int PyFloat_Pack2(double x, unsigned char *p, int le)
123+
124+
Pack a C double as the IEEE 754 binary16 half-precision format.
125+
126+
.. c:function:: int PyFloat_Pack4(double x, unsigned char *p, int le)
127+
128+
Pack a C double as the IEEE 754 binary32 single precision format.
129+
130+
.. c:function:: int PyFloat_Pack8(double x, unsigned char *p, int le)
131+
132+
Pack a C double as the IEEE 754 binary64 double precision format.
133+
134+
135+
Unpack functions
136+
----------------
137+
138+
The unpack routines read 2, 4 or 8 bytes, starting at *p*. *le* is an
139+
:c:type:`int` argument, non-zero if the bytes string is in little-endian format
140+
(exponent last, at ``p+1``, ``p+3`` or ``p+6`` and ``p+7``), zero if big-endian
141+
(exponent first, at *p*).
142+
143+
Return value: The unpacked double. On error, this is ``-1.0`` and
144+
:c:func:`PyErr_Occurred` is true (and an exception is set, most likely
145+
:exc:`OverflowError`).
146+
147+
Note that on a non-IEEE platform this will refuse to unpack a bytes string that
148+
represents a NaN or infinity.
149+
150+
.. c:function:: double PyFloat_Unpack2(const unsigned char *p, int le)
151+
152+
Unpack the IEEE 754 binary16 half-precision format as a C double.
153+
154+
.. c:function:: double PyFloat_Unpack4(const unsigned char *p, int le)
155+
156+
Unpack the IEEE 754 binary32 single precision format as a C double.
157+
158+
.. c:function:: double PyFloat_Unpack8(const unsigned char *p, int le)
159+
160+
Unpack the IEEE 754 binary64 double precision format as a C double.

Doc/library/asyncio-eventloop.rst

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ Creating Futures and Tasks
330330

331331
.. versionadded:: 3.5.2
332332

333-
.. method:: loop.create_task(coro, *, name=None)
333+
.. method:: loop.create_task(coro, *, name=None, context=None)
334334

335335
Schedule the execution of a :ref:`coroutine`.
336336
Return a :class:`Task` object.
@@ -342,17 +342,24 @@ Creating Futures and Tasks
342342
If the *name* argument is provided and not ``None``, it is set as
343343
the name of the task using :meth:`Task.set_name`.
344344

345+
An optional keyword-only *context* argument allows specifying a
346+
custom :class:`contextvars.Context` for the *coro* to run in.
347+
The current context copy is created when no *context* is provided.
348+
345349
.. versionchanged:: 3.8
346350
Added the *name* parameter.
347351

352+
.. versionchanged:: 3.11
353+
Added the *context* parameter.
354+
348355
.. method:: loop.set_task_factory(factory)
349356

350357
Set a task factory that will be used by
351358
:meth:`loop.create_task`.
352359

353360
If *factory* is ``None`` the default task factory will be set.
354361
Otherwise, *factory* must be a *callable* with the signature matching
355-
``(loop, coro)``, where *loop* is a reference to the active
362+
``(loop, coro, context=None)``, where *loop* is a reference to the active
356363
event loop, and *coro* is a coroutine object. The callable
357364
must return a :class:`asyncio.Future`-compatible object.
358365

@@ -922,6 +929,29 @@ convenient.
922929

923930
.. versionadded:: 3.7
924931

932+
.. coroutinemethod:: loop.sock_recvfrom(sock, bufsize)
933+
934+
Receive a datagram of up to *bufsize* from *sock*. Asynchronous version of
935+
:meth:`socket.recvfrom() <socket.socket.recvfrom>`.
936+
937+
Return a tuple of (received data, remote address).
938+
939+
*sock* must be a non-blocking socket.
940+
941+
.. versionadded:: 3.11
942+
943+
.. coroutinemethod:: loop.sock_recvfrom_into(sock, buf, nbytes=0)
944+
945+
Receive a datagram of up to *nbytes* from *sock* into *buf*.
946+
Asynchronous version of
947+
:meth:`socket.recvfrom_into() <socket.socket.recvfrom_into>`.
948+
949+
Return a tuple of (number of bytes received, remote address).
950+
951+
*sock* must be a non-blocking socket.
952+
953+
.. versionadded:: 3.11
954+
925955
.. coroutinemethod:: loop.sock_sendall(sock, data)
926956

927957
Send *data* to the *sock* socket. Asynchronous version of
@@ -940,6 +970,18 @@ convenient.
940970
method, before Python 3.7 it returned a :class:`Future`.
941971
Since Python 3.7, this is an ``async def`` method.
942972

973+
.. coroutinemethod:: loop.sock_sendto(sock, data, address)
974+
975+
Send a datagram from *sock* to *address*.
976+
Asynchronous version of
977+
:meth:`socket.sendto() <socket.socket.sendto>`.
978+
979+
Return the number of bytes sent.
980+
981+
*sock* must be a non-blocking socket.
982+
983+
.. versionadded:: 3.11
984+
943985
.. coroutinemethod:: loop.sock_connect(sock, address)
944986

945987
Connect *sock* to a remote socket at *address*.

Doc/library/asyncio-llapi-index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,18 @@ See also the main documentation section about the
189189
* - ``await`` :meth:`loop.sock_recv_into`
190190
- Receive data from the :class:`~socket.socket` into a buffer.
191191

192+
* - ``await`` :meth:`loop.sock_recvfrom`
193+
- Receive a datagram from the :class:`~socket.socket`.
194+
195+
* - ``await`` :meth:`loop.sock_recvfrom_into`
196+
- Receive a datagram from the :class:`~socket.socket` into a buffer.
197+
192198
* - ``await`` :meth:`loop.sock_sendall`
193199
- Send data to the :class:`~socket.socket`.
194200

201+
* - ``await`` :meth:`loop.sock_sendto`
202+
- Send a datagram via the :class:`~socket.socket` to the given address.
203+
195204
* - ``await`` :meth:`loop.sock_connect`
196205
- Connect the :class:`~socket.socket`.
197206

Doc/library/asyncio-stream.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ and work with streams:
5151
.. coroutinefunction:: open_connection(host=None, port=None, *, \
5252
limit=None, ssl=None, family=0, proto=0, \
5353
flags=0, sock=None, local_addr=None, \
54-
server_hostname=None, ssl_handshake_timeout=None)
54+
server_hostname=None, ssl_handshake_timeout=None, \
55+
happy_eyeballs_delay=None, interleave=None)
5556

5657
Establish a network connection and return a pair of
5758
``(reader, writer)`` objects.
@@ -69,6 +70,9 @@ and work with streams:
6970
.. versionchanged:: 3.7
7071
Added the *ssl_handshake_timeout* parameter.
7172

73+
.. versionadded:: 3.8
74+
Added *happy_eyeballs_delay* and *interleave* parameters.
75+
7276
.. versionchanged:: 3.10
7377
Removed the *loop* parameter.
7478

Doc/library/asyncio-task.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,18 @@ Running an asyncio Program
244244
Creating Tasks
245245
==============
246246

247-
.. function:: create_task(coro, *, name=None)
247+
.. function:: create_task(coro, *, name=None, context=None)
248248

249249
Wrap the *coro* :ref:`coroutine <coroutine>` into a :class:`Task`
250250
and schedule its execution. Return the Task object.
251251

252252
If *name* is not ``None``, it is set as the name of the task using
253253
:meth:`Task.set_name`.
254254

255+
An optional keyword-only *context* argument allows specifying a
256+
custom :class:`contextvars.Context` for the *coro* to run in.
257+
The current context copy is created when no *context* is provided.
258+
255259
The task is executed in the loop returned by :func:`get_running_loop`,
256260
:exc:`RuntimeError` is raised if there is no running loop in
257261
current thread.
@@ -281,6 +285,9 @@ Creating Tasks
281285
.. versionchanged:: 3.8
282286
Added the *name* parameter.
283287

288+
.. versionchanged:: 3.11
289+
Added the *context* parameter.
290+
284291

285292
Sleeping
286293
========

Doc/library/importlib.metadata.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ Python packages or modules::
264264

265265
.. versionadded:: 3.10
266266

267+
.. _distributions:
267268

268269
Distributions
269270
=============

Doc/library/os.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4755,6 +4755,9 @@ Miscellaneous System Information
47554755

47564756
.. availability:: Unix.
47574757

4758+
.. versionchanged:: 3.11
4759+
Add ``'SC_MINSIGSTKSZ'`` name.
4760+
47584761
The following data values are used to support path manipulation operations. These
47594762
are defined for all platforms.
47604763

Doc/library/sqlite3.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ SQLite for internal data storage. It's also possible to prototype an
1717
application using SQLite and then port the code to a larger database such as
1818
PostgreSQL or Oracle.
1919

20-
The sqlite3 module was written by Gerhard Häring. It provides a SQL interface
20+
The sqlite3 module was written by Gerhard Häring. It provides an SQL interface
2121
compliant with the DB-API 2.0 specification described by :pep:`249`, and
2222
requires SQLite 3.7.15 or newer.
2323

@@ -373,7 +373,7 @@ Connection Objects
373373

374374
.. class:: Connection
375375

376-
A SQLite database connection has the following attributes and methods:
376+
An SQLite database connection has the following attributes and methods:
377377

378378
.. attribute:: isolation_level
379379

@@ -589,7 +589,7 @@ Connection Objects
589589

590590
.. method:: load_extension(path)
591591

592-
This routine loads a SQLite extension from a shared library. You have to
592+
This routine loads an SQLite extension from a shared library. You have to
593593
enable extension loading with :meth:`enable_load_extension` before you can
594594
use this routine.
595595

@@ -665,7 +665,7 @@ Connection Objects
665665

666666
.. method:: backup(target, *, pages=-1, progress=None, name="main", sleep=0.250)
667667

668-
This method makes a backup of a SQLite database even while it's being accessed
668+
This method makes a backup of an SQLite database even while it's being accessed
669669
by other clients, or concurrently by the same connection. The copy will be
670670
written into the mandatory argument *target*, that must be another
671671
:class:`Connection` instance.
@@ -1068,7 +1068,7 @@ This is how SQLite types are converted to Python types by default:
10681068
+-------------+----------------------------------------------+
10691069

10701070
The type system of the :mod:`sqlite3` module is extensible in two ways: you can
1071-
store additional Python types in a SQLite database via object adaptation, and
1071+
store additional Python types in an SQLite database via object adaptation, and
10721072
you can let the :mod:`sqlite3` module convert SQLite types to different Python
10731073
types via converters.
10741074

Doc/library/time.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ Functions
257257
:const:`None`, the current time as returned by :func:`.time` is used. The dst
258258
flag is set to ``1`` when DST applies to the given time.
259259

260+
:func:`localtime` may raise :exc:`OverflowError`, if the timestamp is
261+
outside the range of values supported by the platform C :c:func:`localtime`
262+
or :c:func:`gmtime` functions, and :exc:`OSError` on :c:func:`localtime` or
263+
:c:func:`gmtime` failure. It's common for this to be restricted to years
264+
between 1970 and 2038.
265+
260266

261267
.. function:: mktime(t)
262268

Doc/whatsnew/3.11.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ New Modules
226226
Improved Modules
227227
================
228228

229+
asyncio
230+
-------
231+
232+
* Add raw datagram socket functions to the event loop:
233+
:meth:`~asyncio.AbstractEventLoop.sock_sendto`,
234+
:meth:`~asyncio.AbstractEventLoop.sock_recvfrom` and
235+
:meth:`~asyncio.AbstractEventLoop.sock_recvfrom_into`.
236+
(Contributed by Alex Grönholm in :issue:`46805`.)
237+
229238
fractions
230239
---------
231240

@@ -766,6 +775,12 @@ New Features
766775
available directly (via :c:type:`PyCMethod`).
767776
(Contributed by Petr Viktorin in :issue:`46613`.)
768777

778+
* Add new functions to pack and unpack C double (serialize and deserialize):
779+
:c:func:`PyFloat_Pack2`, :c:func:`PyFloat_Pack4`, :c:func:`PyFloat_Pack8`,
780+
:c:func:`PyFloat_Unpack2`, :c:func:`PyFloat_Unpack4` and
781+
:c:func:`PyFloat_Unpack8`.
782+
(Contributed by Victor Stinner in :issue:`46906`.)
783+
769784

770785
Porting to Python 3.11
771786
----------------------

Include/cpython/code.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ typedef uint16_t _Py_CODEUNIT;
2323
# define _Py_MAKECODEUNIT(opcode, oparg) ((opcode)|((oparg)<<8))
2424
#endif
2525

26+
// Use "unsigned char" instead of "uint8_t" here to avoid illegal aliasing:
27+
#define _Py_SET_OPCODE(word, opcode) (((unsigned char *)&(word))[0] = (opcode))
28+
2629

2730
/* Bytecode object */
2831
struct PyCodeObject {

Include/cpython/floatobject.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ typedef struct {
1010
// Macro version of PyFloat_AsDouble() trading safety for speed.
1111
// It doesn't check if op is a double object.
1212
#define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval)
13+
14+
15+
PyAPI_FUNC(int) PyFloat_Pack2(double x, char *p, int le);
16+
PyAPI_FUNC(int) PyFloat_Pack4(double x, char *p, int le);
17+
PyAPI_FUNC(int) PyFloat_Pack8(double x, char *p, int le);
18+
19+
PyAPI_FUNC(double) PyFloat_Unpack2(const char *p, int le);
20+
PyAPI_FUNC(double) PyFloat_Unpack4(const char *p, int le);
21+
PyAPI_FUNC(double) PyFloat_Unpack8(const char *p, int le);

0 commit comments

Comments
 (0)
0