Skip to content

Commit adcba2c

Browse files
Merge branch 'main' into sqlite-rowcount/pythongh-79579-alt
2 parents 7f7943f + 9331087 commit adcba2c

File tree

90 files changed

+1888
-533
lines changed

Some content is hidden

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

90 files changed

+1888
-533
lines changed

Doc/c-api/call.rst

-18
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ Vectorcall Support API
144144
However, the function ``PyVectorcall_NARGS`` should be used to allow
145145
for future extensions.
146146
147-
This function is not part of the :ref:`limited API <stable>`.
148-
149147
.. versionadded:: 3.8
150148
151149
.. c:function:: vectorcallfunc PyVectorcall_Function(PyObject *op)
@@ -158,8 +156,6 @@ Vectorcall Support API
158156
This is mostly useful to check whether or not *op* supports vectorcall,
159157
which can be done by checking ``PyVectorcall_Function(op) != NULL``.
160158
161-
This function is not part of the :ref:`limited API <stable>`.
162-
163159
.. versionadded:: 3.8
164160
165161
.. c:function:: PyObject* PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *dict)
@@ -172,8 +168,6 @@ Vectorcall Support API
172168
It does not check the :const:`Py_TPFLAGS_HAVE_VECTORCALL` flag
173169
and it does not fall back to ``tp_call``.
174170
175-
This function is not part of the :ref:`limited API <stable>`.
176-
177171
.. versionadded:: 3.8
178172
179173
@@ -256,8 +250,6 @@ please see individual documentation for details.
256250
Return the result of the call on success, or raise an exception and return
257251
*NULL* on failure.
258252
259-
This function is not part of the :ref:`limited API <stable>`.
260-
261253
.. versionadded:: 3.9
262254
263255
@@ -343,8 +335,6 @@ please see individual documentation for details.
343335
Return the result of the call on success, or raise an exception and return
344336
*NULL* on failure.
345337
346-
This function is not part of the :ref:`limited API <stable>`.
347-
348338
.. versionadded:: 3.9
349339
350340
@@ -357,8 +347,6 @@ please see individual documentation for details.
357347
Return the result of the call on success, or raise an exception and return
358348
*NULL* on failure.
359349
360-
This function is not part of the :ref:`limited API <stable>`.
361-
362350
.. versionadded:: 3.9
363351
364352
@@ -372,8 +360,6 @@ please see individual documentation for details.
372360
Return the result of the call on success, or raise an exception and return
373361
*NULL* on failure.
374362
375-
This function is not part of the :ref:`limited API <stable>`.
376-
377363
.. versionadded:: 3.9
378364
379365
.. c:function:: PyObject* PyObject_VectorcallDict(PyObject *callable, PyObject *const *args, size_t nargsf, PyObject *kwdict)
@@ -388,8 +374,6 @@ please see individual documentation for details.
388374
already has a dictionary ready to use for the keyword arguments,
389375
but not a tuple for the positional arguments.
390376
391-
This function is not part of the :ref:`limited API <stable>`.
392-
393377
.. versionadded:: 3.9
394378
395379
.. c:function:: PyObject* PyObject_VectorcallMethod(PyObject *name, PyObject *const *args, size_t nargsf, PyObject *kwnames)
@@ -410,8 +394,6 @@ please see individual documentation for details.
410394
Return the result of the call on success, or raise an exception and return
411395
*NULL* on failure.
412396
413-
This function is not part of the :ref:`limited API <stable>`.
414-
415397
.. versionadded:: 3.9
416398
417399

Doc/c-api/init_config.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,8 @@ PyConfig
735735
736736
* ``"utf-8"`` if :c:member:`PyPreConfig.utf8_mode` is non-zero.
737737
* ``"ascii"`` if Python detects that ``nl_langinfo(CODESET)`` announces
738-
the ASCII encoding (or Roman8 encoding on HP-UX), whereas the
739-
``mbstowcs()`` function decodes from a different encoding (usually
740-
Latin1).
738+
the ASCII encoding, whereas the ``mbstowcs()`` function
739+
decodes from a different encoding (usually Latin1).
741740
* ``"utf-8"`` if ``nl_langinfo(CODESET)`` returns an empty string.
742741
* Otherwise, use the :term:`locale encoding`:
743742
``nl_langinfo(CODESET)`` result.

Doc/c-api/structures.rst

-2
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ There are these calling conventions:
321321
or possibly ``NULL`` if there are no keywords. The values of the keyword
322322
arguments are stored in the *args* array, after the positional arguments.
323323
324-
This is not part of the :ref:`limited API <stable>`.
325-
326324
.. versionadded:: 3.7
327325
328326

Doc/c-api/type.rst

+35-3
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,12 @@ The following functions and structs are used to create
193193
.. c:function:: PyObject* PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module, PyType_Spec *spec, PyObject *bases)
194194
195195
Create and return a :ref:`heap type <heap-types>` from the *spec*
196-
(:const:`Py_TPFLAGS_HEAPTYPE`).
196+
(see :const:`Py_TPFLAGS_HEAPTYPE`).
197197
198198
The metaclass *metaclass* is used to construct the resulting type object.
199-
When *metaclass* is ``NULL``, the default :c:type:`PyType_Type` is used
200-
instead. Note that metaclasses that override
199+
When *metaclass* is ``NULL``, the metaclass is derived from *bases*
200+
(or *Py_tp_base[s]* slots if *bases* is ``NULL``, see below).
201+
Note that metaclasses that override
201202
:c:member:`~PyTypeObject.tp_new` are not supported.
202203
203204
The *bases* argument can be used to specify base classes; it can either
@@ -215,6 +216,19 @@ The following functions and structs are used to create
215216
216217
This function calls :c:func:`PyType_Ready` on the new type.
217218
219+
Note that this function does *not* fully match the behavior of
220+
calling :py:class:`type() <type>` or using the :keyword:`class` statement.
221+
With user-provided base types or metaclasses, prefer
222+
:ref:`calling <capi-call>` :py:class:`type` (or the metaclass)
223+
over ``PyType_From*`` functions.
224+
Specifically:
225+
226+
* :py:meth:`~object.__new__` is not called on the new class
227+
(and it must be set to ``type.__new__``).
228+
* :py:meth:`~object.__init__` is not called on the new class.
229+
* :py:meth:`~object.__init_subclass__` is not called on any bases.
230+
* :py:meth:`~object.__set_name__` is not called on new descriptors.
231+
218232
.. versionadded:: 3.12
219233
220234
.. c:function:: PyObject* PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
@@ -228,17 +242,33 @@ The following functions and structs are used to create
228242
The function now accepts a single class as the *bases* argument and
229243
``NULL`` as the ``tp_doc`` slot.
230244
245+
.. versionchanged:: 3.12
246+
247+
The function now finds and uses a metaclass corresponding to the provided
248+
base classes. Previously, only :class:`type` instances were returned.
249+
231250
232251
.. c:function:: PyObject* PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
233252
234253
Equivalent to ``PyType_FromMetaclass(NULL, NULL, spec, bases)``.
235254
236255
.. versionadded:: 3.3
237256
257+
.. versionchanged:: 3.12
258+
259+
The function now finds and uses a metaclass corresponding to the provided
260+
base classes. Previously, only :class:`type` instances were returned.
261+
238262
.. c:function:: PyObject* PyType_FromSpec(PyType_Spec *spec)
239263
240264
Equivalent to ``PyType_FromMetaclass(NULL, NULL, spec, NULL)``.
241265
266+
.. versionchanged:: 3.12
267+
268+
The function now finds and uses a metaclass corresponding to the
269+
base classes provided in *Py_tp_base[s]* slots.
270+
Previously, only :class:`type` instances were returned.
271+
242272
.. c:type:: PyType_Spec
243273
244274
Structure defining a type's behavior.
@@ -266,6 +296,8 @@ The following functions and structs are used to create
266296
Array of :c:type:`PyType_Slot` structures.
267297
Terminated by the special slot value ``{0, NULL}``.
268298
299+
Each slot ID should be specified at most once.
300+
269301
.. c:type:: PyType_Slot
270302
271303
Structure defining optional functionality of a type, containing a slot ID

Doc/c-api/typeobj.rst

-6
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,6 @@ and :c:type:`PyType_Type` effectively act as defaults.)
727727
When a user sets :attr:`__call__` in Python code, only *tp_call* is updated,
728728
likely making it inconsistent with the vectorcall function.
729729

730-
.. note::
731-
732-
The semantics of the ``tp_vectorcall_offset`` slot are provisional and
733-
expected to be finalized in Python 3.9.
734-
If you use vectorcall, plan for updating your code for Python 3.9.
735-
736730
.. versionchanged:: 3.8
737731

738732
Before version 3.8, this slot was named ``tp_print``.

Doc/faq/library.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,14 @@ including :func:`~shutil.copyfile`, :func:`~shutil.copytree`, and
483483
How do I copy a file?
484484
---------------------
485485
486-
The :mod:`shutil` module contains a :func:`~shutil.copyfile` function. Note
487-
that on MacOS 9 it doesn't copy the resource fork and Finder info.
486+
The :mod:`shutil` module contains a :func:`~shutil.copyfile` function.
487+
Note that on Windows NTFS volumes, it does not copy
488+
`alternate data streams
489+
<https://en.wikipedia.org/wiki/NTFS#Alternate_data_stream_(ADS)>`_
490+
nor `resource forks <https://en.wikipedia.org/wiki/Resource_fork>`__
491+
on macOS HFS+ volumes, though both are now rarely used.
492+
It also doesn't copy file permissions and metadata, though using
493+
:func:`shutil.copy2` instead will preserve most (though not all) of it.
488494
489495
490496
How do I read (or write) binary data?

Doc/howto/logging-cookbook.rst

+89
Original file line numberDiff line numberDiff line change
@@ -3022,6 +3022,95 @@ refer to the comments in the code snippet for more detailed information.
30223022
if __name__=='__main__':
30233023
main()
30243024
3025+
Logging to syslog with RFC5424 support
3026+
--------------------------------------
3027+
3028+
Although :rfc:`5424` dates from 2009, most syslog servers are configured by detault to
3029+
use the older :rfc:`3164`, which hails from 2001. When ``logging`` was added to Python
3030+
in 2003, it supported the earlier (and only existing) protocol at the time. Since
3031+
RFC5424 came out, as there has not been widespread deployment of it in syslog
3032+
servers, the :class:`~logging.handlers.SysLogHandler` functionality has not been
3033+
updated.
3034+
3035+
RFC 5424 contains some useful features such as support for structured data, and if you
3036+
need to be able to log to a syslog server with support for it, you can do so with a
3037+
subclassed handler which looks something like this::
3038+
3039+
import datetime
3040+
import logging.handlers
3041+
import re
3042+
import socket
3043+
import time
3044+
3045+
class SysLogHandler5424(logging.handlers.SysLogHandler):
3046+
3047+
tz_offset = re.compile(r'([+-]\d{2})(\d{2})$')
3048+
escaped = re.compile(r'([\]"\\])')
3049+
3050+
def __init__(self, *args, **kwargs):
3051+
self.msgid = kwargs.pop('msgid', None)
3052+
self.appname = kwargs.pop('appname', None)
3053+
super().__init__(*args, **kwargs)
3054+
3055+
def format(self, record):
3056+
version = 1
3057+
asctime = datetime.datetime.fromtimestamp(record.created).isoformat()
3058+
m = self.tz_offset.match(time.strftime('%z'))
3059+
has_offset = False
3060+
if m and time.timezone:
3061+
hrs, mins = m.groups()
3062+
if int(hrs) or int(mins):
3063+
has_offset = True
3064+
if not has_offset:
3065+
asctime += 'Z'
3066+
else:
3067+
asctime += f'{hrs}:{mins}'
3068+
try:
3069+
hostname = socket.gethostname()
3070+
except Exception:
3071+
hostname = '-'
3072+
appname = self.appname or '-'
3073+
procid = record.process
3074+
msgid = '-'
3075+
msg = super().format(record)
3076+
sdata = '-'
3077+
if hasattr(record, 'structured_data'):
3078+
sd = record.structured_data
3079+
# This should be a dict where the keys are SD-ID and the value is a
3080+
# dict mapping PARAM-NAME to PARAM-VALUE (refer to the RFC for what these
3081+
# mean)
3082+
# There's no error checking here - it's purely for illustration, and you
3083+
# can adapt this code for use in production environments
3084+
parts = []
3085+
3086+
def replacer(m):
3087+
g = m.groups()
3088+
return '\\' + g[0]
3089+
3090+
for sdid, dv in sd.items():
3091+
part = f'[{sdid}'
3092+
for k, v in dv.items():
3093+
s = str(v)
3094+
s = self.escaped.sub(replacer, s)
3095+
part += f' {k}="{s}"'
3096+
part += ']'
3097+
parts.append(part)
3098+
sdata = ''.join(parts)
3099+
return f'{version} {asctime} {hostname} {appname} {procid} {msgid} {sdata} {msg}'
3100+
3101+
You'll need to be familiar with RFC 5424 to fully understand the above code, and it
3102+
may be that you have slightly different needs (e.g. for how you pass structural data
3103+
to the log). Nevertheless, the above should be adaptable to your speciric needs. With
3104+
the above handler, you'd pass structured data using something like this::
3105+
3106+
sd = {
3107+
'foo@12345': {'bar': 'baz', 'baz': 'bozz', 'fizz': r'buzz'},
3108+
'foo@54321': {'rab': 'baz', 'zab': 'bozz', 'zzif': r'buzz'}
3109+
}
3110+
extra = {'structured_data': sd}
3111+
i = 1
3112+
logger.debug('Message %d', i, extra=extra)
3113+
30253114

30263115
.. patterns-to-avoid:
30273116

Doc/howto/sockets.rst

+12-7
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,25 @@ Binary Data
252252
-----------
253253

254254
It is perfectly possible to send binary data over a socket. The major problem is
255-
that not all machines use the same formats for binary data. For example, a
256-
Motorola chip will represent a 16 bit integer with the value 1 as the two hex
257-
bytes 00 01. Intel and DEC, however, are byte-reversed - that same 1 is 01 00.
255+
that not all machines use the same formats for binary data. For example,
256+
`network byte order <https://en.wikipedia.org/wiki/Endianness#Networking>`_
257+
is big-endian, with the most significant byte first,
258+
so a 16 bit integer with the value ``1`` would be the two hex bytes ``00 01``.
259+
However, most common processors (x86/AMD64, ARM, RISC-V), are little-endian,
260+
with the least significant byte first - that same ``1`` would be ``01 00``.
261+
258262
Socket libraries have calls for converting 16 and 32 bit integers - ``ntohl,
259263
htonl, ntohs, htons`` where "n" means *network* and "h" means *host*, "s" means
260264
*short* and "l" means *long*. Where network order is host order, these do
261265
nothing, but where the machine is byte-reversed, these swap the bytes around
262266
appropriately.
263267

264-
In these days of 32 bit machines, the ascii representation of binary data is
268+
In these days of 64-bit machines, the ASCII representation of binary data is
265269
frequently smaller than the binary representation. That's because a surprising
266-
amount of the time, all those longs have the value 0, or maybe 1. The string "0"
267-
would be two bytes, while binary is four. Of course, this doesn't fit well with
268-
fixed-length messages. Decisions, decisions.
270+
amount of the time, most integers have the value 0, or maybe 1.
271+
The string ``"0"`` would be two bytes, while a full 64-bit integer would be 8.
272+
Of course, this doesn't fit well with fixed-length messages.
273+
Decisions, decisions.
269274

270275

271276
Disconnecting

Doc/library/logging.rst

+10-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@ is that all Python modules can participate in logging, so your application log
3030
can include your own messages integrated with messages from third-party
3131
modules.
3232

33+
The simplest example:
34+
35+
.. code-block:: none
36+
37+
>>> import logging
38+
>>> logging.warning('Watch out!')
39+
WARNING:root:Watch out!
40+
3341
The module provides a lot of functionality and flexibility. If you are
34-
unfamiliar with logging, the best way to get to grips with it is to see the
35-
tutorials (see the links on the right).
42+
unfamiliar with logging, the best way to get to grips with it is to view the
43+
tutorials (**see the links above and on the right**).
3644

3745
The basic classes defined by the module, together with their functions, are
3846
listed below.

Doc/library/mmap.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
102102

103103
To ensure validity of the created memory mapping the file specified
104104
by the descriptor *fileno* is internally automatically synchronized
105-
with physical backing store on macOS and OpenVMS.
105+
with the physical backing store on macOS.
106106

107107
This example shows a simple way of using :class:`~mmap.mmap`::
108108

Doc/library/os.path.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ the :mod:`glob` module.)
469469
("c:", "/dir")
470470

471471
If the path contains a UNC path, drive will contain the host name
472-
and share, up to but not including the fourth separator::
472+
and share::
473473

474474
>>> splitdrive("//host/computer/dir")
475475
("//host/computer", "/dir")

0 commit comments

Comments
 (0)