Skip to content

Commit 2a843bc

Browse files
committed
merge
2 parents 3c4edd8 + 6f4d64b commit 2a843bc

126 files changed

Lines changed: 2517 additions & 1071 deletions

File tree

Some content is hidden

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

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ Doc/c-api/stable.rst @encukou
207207
**/*bisect* @rhettinger
208208
**/*heapq* @rhettinger
209209
**/*functools* @rhettinger
210-
**/*decimal* @rhettinger
211210

212211
**/*dataclasses* @ericvsmith
213212

Doc/c-api/init_config.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,19 +1248,24 @@ PyConfig
12481248
12491249
.. c:member:: int perf_profiling
12501250
1251-
Enable compatibility mode with the perf profiler?
1251+
Enable the Linux ``perf`` profiler support?
12521252
1253-
If non-zero, initialize the perf trampoline. See :ref:`perf_profiling`
1254-
for more information.
1253+
If equals to ``1``, enable support for the Linux ``perf`` profiler.
12551254
1256-
Set by :option:`-X perf <-X>` command-line option and by the
1257-
:envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable for perf support
1258-
with stack pointers and :option:`-X perf_jit <-X>` command-line option
1259-
and by the :envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable for perf
1260-
support with DWARF JIT information.
1255+
If equals to ``2``, enable support for the Linux ``perf`` profiler with
1256+
DWARF JIT support.
1257+
1258+
Set to ``1`` by :option:`-X perf <-X>` command-line option and the
1259+
:envvar:`PYTHONPERFSUPPORT` environment variable.
1260+
1261+
Set to ``2`` by the :option:`-X perf_jit <-X>` command-line option and
1262+
the :envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable.
12611263
12621264
Default: ``-1``.
12631265
1266+
.. seealso::
1267+
See :ref:`perf_profiling` for more information.
1268+
12641269
.. versionadded:: 3.12
12651270
12661271
.. c:member:: int use_environment

Doc/c-api/long.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
159159
.. versionadded:: 3.13
160160
161161
162-
.. XXX alias PyLong_AS_LONG (for now)
163162
.. c:function:: long PyLong_AsLong(PyObject *obj)
164163
165164
.. index::
@@ -181,6 +180,16 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
181180
.. versionchanged:: 3.10
182181
This function will no longer use :meth:`~object.__int__`.
183182
183+
.. c:namespace:: NULL
184+
185+
.. c:function:: long PyLong_AS_LONG(PyObject *obj)
186+
187+
A :term:`soft deprecated` alias.
188+
Exactly equivalent to the preferred ``PyLong_AsLong``. In particular,
189+
it can fail with :exc:`OverflowError` or another exception.
190+
191+
.. deprecated:: 3.14
192+
The function is soft deprecated.
184193
185194
.. c:function:: int PyLong_AsInt(PyObject *obj)
186195

Doc/c-api/unicode.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ These APIs can be used to work with surrogates:
317317
318318
.. c:function:: Py_UCS4 Py_UNICODE_JOIN_SURROGATES(Py_UCS4 high, Py_UCS4 low)
319319
320-
Join two surrogate characters and return a single :c:type:`Py_UCS4` value.
320+
Join two surrogate code points and return a single :c:type:`Py_UCS4` value.
321321
*high* and *low* are respectively the leading and trailing surrogates in a
322322
surrogate pair. *high* must be in the range [0xD800; 0xDBFF] and *low* must
323323
be in the range [0xDC00; 0xDFFF].
@@ -338,6 +338,8 @@ APIs:
338338
This is the recommended way to allocate a new Unicode object. Objects
339339
created using this function are not resizable.
340340
341+
On error, set an exception and return ``NULL``.
342+
341343
.. versionadded:: 3.3
342344
343345
@@ -614,6 +616,8 @@ APIs:
614616
615617
Return the length of the Unicode object, in code points.
616618
619+
On error, set an exception and return ``-1``.
620+
617621
.. versionadded:: 3.3
618622
619623
@@ -657,6 +661,8 @@ APIs:
657661
not out of bounds, and that the object can be modified safely (i.e. that it
658662
its reference count is one).
659663
664+
Return ``0`` on success, ``-1`` on error with an exception set.
665+
660666
.. versionadded:: 3.3
661667
662668
@@ -666,6 +672,8 @@ APIs:
666672
Unicode object and the index is not out of bounds, in contrast to
667673
:c:func:`PyUnicode_READ_CHAR`, which performs no error checking.
668674
675+
Return character on success, ``-1`` on error with an exception set.
676+
669677
.. versionadded:: 3.3
670678
671679
@@ -674,6 +682,7 @@ APIs:
674682
675683
Return a substring of *unicode*, from character index *start* (included) to
676684
character index *end* (excluded). Negative indices are not supported.
685+
On error, set an exception and return ``NULL``.
677686
678687
.. versionadded:: 3.3
679688
@@ -990,6 +999,9 @@ These are the UTF-8 codec APIs:
990999
object. Error handling is "strict". Return ``NULL`` if an exception was
9911000
raised by the codec.
9921001
1002+
The function fails if the string contains surrogate code points
1003+
(``U+D800`` - ``U+DFFF``).
1004+
9931005
9941006
.. c:function:: const char* PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *size)
9951007
@@ -1002,6 +1014,9 @@ These are the UTF-8 codec APIs:
10021014
On error, set an exception, set *size* to ``-1`` (if it's not NULL) and
10031015
return ``NULL``.
10041016
1017+
The function fails if the string contains surrogate code points
1018+
(``U+D800`` - ``U+DFFF``).
1019+
10051020
This caches the UTF-8 representation of the string in the Unicode object, and
10061021
subsequent calls will return a pointer to the same buffer. The caller is not
10071022
responsible for deallocating the buffer. The buffer is deallocated and
@@ -1429,8 +1444,9 @@ They all return ``NULL`` or ``-1`` if an exception occurs.
14291444
Compare a Unicode object with a char buffer which is interpreted as
14301445
being UTF-8 or ASCII encoded and return true (``1``) if they are equal,
14311446
or false (``0``) otherwise.
1432-
If the Unicode object contains surrogate characters or
1433-
the C string is not valid UTF-8, false (``0``) is returned.
1447+
If the Unicode object contains surrogate code points
1448+
(``U+D800`` - ``U+DFFF``) or the C string is not valid UTF-8,
1449+
false (``0``) is returned.
14341450
14351451
This function does not raise exceptions.
14361452

Doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@
413413
\let\endVerbatim=\endOriginalVerbatim
414414
\setcounter{tocdepth}{2}
415415
''',
416-
# The paper size ('letter' or 'a4').
417-
'papersize': 'a4',
416+
# The paper size ('letterpaper' or 'a4paper').
417+
'papersize': 'a4paper',
418418
# The font size ('10pt', '11pt' or '12pt').
419419
'pointsize': '10pt',
420420
}

Doc/deprecations/pending-removal-in-3.16.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ Pending Removal in Python 3.16
1818
Use the ``'w'`` format code (:c:type:`Py_UCS4`)
1919
for Unicode characters instead.
2020

21+
* :mod:`asyncio`:
22+
23+
* :mod:`asyncio`:
24+
:func:`!asyncio.iscoroutinefunction` is deprecated
25+
and will be removed in Python 3.16,
26+
use :func:`inspect.iscoroutinefunction` instead.
27+
(Contributed by Jiahao Li and Kumar Aditya in :gh:`122875`.)
28+
2129
* :mod:`shutil`:
2230

2331
* The :class:`!ExecError` exception

Doc/howto/sorting.rst

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ lists. In contrast, the :func:`sorted` function accepts any iterable.
4747
Key Functions
4848
=============
4949

50-
Both :meth:`list.sort` and :func:`sorted` have a *key* parameter to specify a
51-
function (or other callable) to be called on each list element prior to making
50+
The :meth:`list.sort` method and the functions :func:`sorted`,
51+
:func:`min`, :func:`max`, :func:`heapq.nsmallest`, and
52+
:func:`heapq.nlargest` have a *key* parameter to specify a function (or
53+
other callable) to be called on each list element prior to making
5254
comparisons.
5355

54-
For example, here's a case-insensitive string comparison:
56+
For example, here's a case-insensitive string comparison using
57+
:meth:`str.casefold`:
5558

5659
.. doctest::
5760

@@ -272,6 +275,70 @@ to make it usable as a key function::
272275

273276
sorted(words, key=cmp_to_key(strcoll)) # locale-aware sort order
274277

278+
Strategies For Unorderable Types and Values
279+
===========================================
280+
281+
A number of type and value issues can arise when sorting.
282+
Here are some strategies that can help:
283+
284+
* Convert non-comparable input types to strings prior to sorting:
285+
286+
.. doctest::
287+
288+
>>> data = ['twelve', '11', 10]
289+
>>> sorted(map(str, data))
290+
['10', '11', 'twelve']
291+
292+
This is needed because most cross-type comparisons raise a
293+
:exc:`TypeError`.
294+
295+
* Remove special values prior to sorting:
296+
297+
.. doctest::
298+
299+
>>> from math import isnan
300+
>>> from itertools import filterfalse
301+
>>> data = [3.3, float('nan'), 1.1, 2.2]
302+
>>> sorted(filterfalse(isnan, data))
303+
[1.1, 2.2, 3.3]
304+
305+
This is needed because the `IEEE-754 standard
306+
<https://en.wikipedia.org/wiki/IEEE_754>`_ specifies that, "Every NaN
307+
shall compare unordered with everything, including itself."
308+
309+
Likewise, ``None`` can be stripped from datasets as well:
310+
311+
.. doctest::
312+
313+
>>> data = [3.3, None, 1.1, 2.2]
314+
>>> sorted(x for x in data if x is not None)
315+
[1.1, 2.2, 3.3]
316+
317+
This is needed because ``None`` is not comparable to other types.
318+
319+
* Convert mapping types into sorted item lists before sorting:
320+
321+
.. doctest::
322+
323+
>>> data = [{'a': 1}, {'b': 2}]
324+
>>> sorted(data, key=lambda d: sorted(d.items()))
325+
[{'a': 1}, {'b': 2}]
326+
327+
This is needed because dict-to-dict comparisons raise a
328+
:exc:`TypeError`.
329+
330+
* Convert set types into sorted lists before sorting:
331+
332+
.. doctest::
333+
334+
>>> data = [{'a', 'b', 'c'}, {'b', 'c', 'd'}]
335+
>>> sorted(map(sorted, data))
336+
[['a', 'b', 'c'], ['b', 'c', 'd']]
337+
338+
This is needed because the elements contained in set types do not have a
339+
deterministic order. For example, ``list({'a', 'b'})`` may produce
340+
either ``['a', 'b']`` or ``['b', 'a']``.
341+
275342
Odds and Ends
276343
=============
277344

Doc/library/argparse.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ Sub-commands
18231823
>>>
18241824
>>> # create the parser for the "b" command
18251825
>>> parser_b = subparsers.add_parser('b', help='b help')
1826-
>>> parser_b.add_argument('--baz', choices='XYZ', help='baz help')
1826+
>>> parser_b.add_argument('--baz', choices=('X', 'Y', 'Z'), help='baz help')
18271827
>>>
18281828
>>> # parse some argument lists
18291829
>>> parser.parse_args(['a', '12'])

Doc/library/dataclasses.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Module contents
231231
follows a field with a default value. This is true whether this
232232
occurs in a single class, or as a result of class inheritance.
233233

234-
.. function:: field(*, default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None, kw_only=MISSING)
234+
.. function:: field(*, default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None, kw_only=MISSING, doc=None)
235235

236236
For common and simple use cases, no other functionality is
237237
required. There are, however, some dataclass features that
@@ -300,6 +300,10 @@ Module contents
300300

301301
.. versionadded:: 3.10
302302

303+
- ``doc``: optional docstring for this field.
304+
305+
.. versionadded:: 3.13
306+
303307
If the default value of a field is specified by a call to
304308
:func:`!field`, then the class attribute for this field will be
305309
replaced by the specified *default* value. If *default* is not

Doc/library/functools.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,25 @@ The :mod:`functools` module defines the following functions:
543543
... print(arg.real, arg.imag)
544544
...
545545

546+
For code that dispatches on a collections type (e.g., ``list``), but wants
547+
to typehint the items of the collection (e.g., ``list[int]``), the
548+
dispatch type should be passed explicitly to the decorator itself with the
549+
typehint going into the function definition::
550+
551+
>>> @fun.register(list)
552+
... def _(arg: list[int], verbose=False):
553+
... if verbose:
554+
... print("Enumerate this:")
555+
... for i, elem in enumerate(arg):
556+
... print(i, elem)
557+
558+
.. note::
559+
560+
At runtime the function will dispatch on an instance of a list regardless
561+
of the type contained within the list i.e. ``[1,2,3]`` will be
562+
dispatched the same as ``["foo", "bar", "baz"]``. The annotation
563+
provided in this example is for static type checkers only and has no
564+
runtime impact.
546565

547566
To enable registering :term:`lambdas<lambda>` and pre-existing functions,
548567
the :func:`register` attribute can also be used in a functional form::

0 commit comments

Comments
 (0)