Skip to content

Commit a9af20a

Browse files
committed
Merge branch 'main' into fastmock
* main: pythongh-89727: Fix os.walk RecursionError on deep trees (python#99803) Docs: Don't upload CI artifacts (python#100330) pythongh-94912: Added marker for non-standard coroutine function detection (python#99247) Correct CVE-2020-10735 documentation (python#100306) pythongh-100272: Fix JSON serialization of OrderedDict (pythonGH-100273) pythongh-93649: Split tracemalloc tests from _testcapimodule.c (python#99551) Docs: Use `PY_VERSION_HEX` for version comparison (python#100179) pythongh-97909: Fix markup for `PyMethodDef` members (python#100089) pythongh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (python#99890) pythongh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (python#99890) pythonGH-98831: Add DECREF_INPUTS(), expanding to DECREF() each stack input (python#100205) pythongh-78707: deprecate passing >1 argument to `PurePath.[is_]relative_to()` (pythonGH-94469)
2 parents 6595272 + 797edb2 commit a9af20a

33 files changed

+615
-393
lines changed

.github/workflows/doc.yml

-10
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,8 @@ jobs:
5050
run: make -C Doc/ venv
5151
- name: 'Check documentation'
5252
run: make -C Doc/ check
53-
- name: 'Upload NEWS'
54-
uses: actions/upload-artifact@v3
55-
with:
56-
name: NEWS
57-
path: Doc/build/NEWS
5853
- name: 'Build HTML documentation'
5954
run: make -C Doc/ SPHINXOPTS="-q" SPHINXERRORHANDLING="-W --keep-going" html
60-
- name: 'Upload docs'
61-
uses: actions/upload-artifact@v3
62-
with:
63-
name: doc-html
64-
path: Doc/build/html
6555

6656
# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
6757
doctest:

Doc/c-api/apiabiversion.rst

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ See :ref:`stable` for a discussion of API and ABI stability across versions.
5858
Thus ``3.4.1a2`` is hexversion ``0x030401a2`` and ``3.10.0`` is
5959
hexversion ``0x030a00f0``.
6060

61+
Use this for numeric comparisons, e.g. ``#if PY_VERSION_HEX >= ...``.
62+
6163
This version is also available via the symbol :data:`Py_Version`.
6264

6365
.. c:var:: const unsigned long Py_Version

Doc/c-api/structures.rst

+18-17
Original file line numberDiff line numberDiff line change
@@ -228,29 +228,30 @@ Implementing functions and methods
228228
Structure used to describe a method of an extension type. This structure has
229229
four fields:
230230
231-
+------------------+---------------+-------------------------------+
232-
| Field | C Type | Meaning |
233-
+==================+===============+===============================+
234-
| :attr:`ml_name` | const char \* | name of the method |
235-
+------------------+---------------+-------------------------------+
236-
| :attr:`ml_meth` | PyCFunction | pointer to the C |
237-
| | | implementation |
238-
+------------------+---------------+-------------------------------+
239-
| :attr:`ml_flags` | int | flag bits indicating how the |
240-
| | | call should be constructed |
241-
+------------------+---------------+-------------------------------+
242-
| :attr:`ml_doc` | const char \* | points to the contents of the |
243-
| | | docstring |
244-
+------------------+---------------+-------------------------------+
245-
246-
The :attr:`ml_meth` is a C function pointer. The functions may be of different
231+
.. c:member:: const char* ml_name
232+
233+
name of the method
234+
235+
.. c:member:: PyCFunction ml_meth
236+
237+
pointer to the C implementation
238+
239+
.. c:member:: int ml_flags
240+
241+
flags bits indicating how the call should be constructed
242+
243+
.. c:member:: const char* ml_doc
244+
245+
points to the contents of the docstring
246+
247+
The :c:member:`ml_meth` is a C function pointer. The functions may be of different
247248
types, but they always return :c:expr:`PyObject*`. If the function is not of
248249
the :c:type:`PyCFunction`, the compiler will require a cast in the method table.
249250
Even though :c:type:`PyCFunction` defines the first parameter as
250251
:c:expr:`PyObject*`, it is common that the method implementation uses the
251252
specific C type of the *self* object.
252253
253-
The :attr:`ml_flags` field is a bitfield which can include the following flags.
254+
The :c:member:`ml_flags` field is a bitfield which can include the following flags.
254255
The individual flags indicate either a calling convention or a binding
255256
convention.
256257

Doc/library/inspect.rst

+23-2
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,36 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
343343

344344
.. function:: iscoroutinefunction(object)
345345

346-
Return ``True`` if the object is a :term:`coroutine function`
347-
(a function defined with an :keyword:`async def` syntax).
346+
Return ``True`` if the object is a :term:`coroutine function` (a function
347+
defined with an :keyword:`async def` syntax), a :func:`functools.partial`
348+
wrapping a :term:`coroutine function`, or a sync function marked with
349+
:func:`markcoroutinefunction`.
348350

349351
.. versionadded:: 3.5
350352

351353
.. versionchanged:: 3.8
352354
Functions wrapped in :func:`functools.partial` now return ``True`` if the
353355
wrapped function is a :term:`coroutine function`.
354356

357+
.. versionchanged:: 3.12
358+
Sync functions marked with :func:`markcoroutinefunction` now return
359+
``True``.
360+
361+
362+
.. function:: markcoroutinefunction(func)
363+
364+
Decorator to mark a callable as a :term:`coroutine function` if it would not
365+
otherwise be detected by :func:`iscoroutinefunction`.
366+
367+
This may be of use for sync functions that return a :term:`coroutine`, if
368+
the function is passed to an API that requires :func:`iscoroutinefunction`.
369+
370+
When possible, using an :keyword:`async def` function is preferred. Also
371+
acceptable is calling the function and testing the return with
372+
:func:`iscoroutine`.
373+
374+
.. versionadded:: 3.12
375+
355376

356377
.. function:: iscoroutine(object)
357378

Doc/library/pathlib.rst

+11-3
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ Pure paths provide the following methods and properties:
490490
True
491491

492492

493-
.. method:: PurePath.is_relative_to(*other)
493+
.. method:: PurePath.is_relative_to(other)
494494

495495
Return whether or not this path is relative to the *other* path.
496496

@@ -502,6 +502,10 @@ Pure paths provide the following methods and properties:
502502

503503
.. versionadded:: 3.9
504504

505+
.. deprecated-removed:: 3.12 3.14
506+
507+
Passing additional arguments is deprecated; if supplied, they are joined
508+
with *other*.
505509

506510
.. method:: PurePath.is_reserved()
507511

@@ -564,7 +568,7 @@ Pure paths provide the following methods and properties:
564568
True
565569

566570

567-
.. method:: PurePath.relative_to(*other, walk_up=False)
571+
.. method:: PurePath.relative_to(other, walk_up=False)
568572

569573
Compute a version of this path relative to the path represented by
570574
*other*. If it's impossible, :exc:`ValueError` is raised::
@@ -581,7 +585,7 @@ Pure paths provide the following methods and properties:
581585
raise ValueError(error_message.format(str(self), str(formatted)))
582586
ValueError: '/etc/passwd' is not in the subpath of '/usr' OR one path is relative and the other is absolute.
583587

584-
When *walk_up* is False (the default), the path must start with *other*.
588+
When *walk_up* is False (the default), the path must start with *other*.
585589
When the argument is True, ``..`` entries may be added to form the
586590
relative path. In all other cases, such as the paths referencing
587591
different drives, :exc:`ValueError` is raised.::
@@ -605,6 +609,10 @@ When *walk_up* is False (the default), the path must start with *other*.
605609
.. versionadded:: 3.12
606610
The *walk_up* argument (old behavior is the same as ``walk_up=False``).
607611

612+
.. deprecated-removed:: 3.12 3.14
613+
614+
Passing additional positional arguments is deprecated; if supplied,
615+
they are joined with *other*.
608616

609617
.. method:: PurePath.with_name(name)
610618

Doc/library/stdtypes.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -5480,7 +5480,7 @@ to mitigate denial of service attacks. This limit *only* applies to decimal or
54805480
other non-power-of-two number bases. Hexadecimal, octal, and binary conversions
54815481
are unlimited. The limit can be configured.
54825482

5483-
The :class:`int` type in CPython is an abitrary length number stored in binary
5483+
The :class:`int` type in CPython is an arbitrary length number stored in binary
54845484
form (commonly known as a "bignum"). There exists no algorithm that can convert
54855485
a string to a binary integer or a binary integer to a string in linear time,
54865486
*unless* the base is a power of 2. Even the best known algorithms for base 10
@@ -5544,7 +5544,7 @@ and :class:`str` or :class:`bytes`:
55445544
* ``int(string)`` with default base 10.
55455545
* ``int(string, base)`` for all bases that are not a power of 2.
55465546
* ``str(integer)``.
5547-
* ``repr(integer)``
5547+
* ``repr(integer)``.
55485548
* any other string conversion to base 10, for example ``f"{integer}"``,
55495549
``"{}".format(integer)``, or ``b"%d" % integer``.
55505550

@@ -5572,7 +5572,7 @@ command line flag to configure the limit:
55725572
:envvar:`PYTHONINTMAXSTRDIGITS` or :option:`-X int_max_str_digits <-X>`.
55735573
If both the env var and the ``-X`` option are set, the ``-X`` option takes
55745574
precedence. A value of *-1* indicates that both were unset, thus a value of
5575-
:data:`sys.int_info.default_max_str_digits` was used during initilization.
5575+
:data:`sys.int_info.default_max_str_digits` was used during initialization.
55765576

55775577
From code, you can inspect the current limit and set a new one using these
55785578
:mod:`sys` APIs:

Doc/whatsnew/3.11.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,7 @@ Porting to Python 3.11
23192319
can define the following macros and use them throughout
23202320
the code (credit: these were copied from the ``mypy`` codebase)::
23212321

2322-
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 8
2322+
#if PY_VERSION_HEX >= 0x03080000
23232323
# define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN(op, dealloc)
23242324
# define CPy_TRASHCAN_END(op) Py_TRASHCAN_END
23252325
#else

Doc/whatsnew/3.12.rst

+6
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ asyncio
225225
a custom event loop factory.
226226
(Contributed by Kumar Aditya in :gh:`99388`.)
227227

228+
inspect
229+
-------
230+
231+
* Add :func:`inspect.markcoroutinefunction` to mark sync functions that return
232+
a :term:`coroutine` for use with :func:`iscoroutinefunction`.
233+
(Contributed Carlton Gibson in :gh:`99247`.)
228234

229235
pathlib
230236
-------

Lib/inspect.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"ismodule",
126126
"isroutine",
127127
"istraceback",
128+
"markcoroutinefunction",
128129
"signature",
129130
"stack",
130131
"trace",
@@ -391,12 +392,33 @@ def isgeneratorfunction(obj):
391392
See help(isfunction) for a list of attributes."""
392393
return _has_code_flag(obj, CO_GENERATOR)
393394

395+
# A marker for markcoroutinefunction and iscoroutinefunction.
396+
_is_coroutine_marker = object()
397+
398+
def _has_coroutine_mark(f):
399+
while ismethod(f):
400+
f = f.__func__
401+
f = functools._unwrap_partial(f)
402+
if not (isfunction(f) or _signature_is_functionlike(f)):
403+
return False
404+
return getattr(f, "_is_coroutine_marker", None) is _is_coroutine_marker
405+
406+
def markcoroutinefunction(func):
407+
"""
408+
Decorator to ensure callable is recognised as a coroutine function.
409+
"""
410+
if hasattr(func, '__func__'):
411+
func = func.__func__
412+
func._is_coroutine_marker = _is_coroutine_marker
413+
return func
414+
394415
def iscoroutinefunction(obj):
395416
"""Return true if the object is a coroutine function.
396417
397-
Coroutine functions are defined with "async def" syntax.
418+
Coroutine functions are normally defined with "async def" syntax, but may
419+
be marked via markcoroutinefunction.
398420
"""
399-
return _has_code_flag(obj, CO_COROUTINE)
421+
return _has_code_flag(obj, CO_COROUTINE) or _has_coroutine_mark(obj)
400422

401423
def isasyncgenfunction(obj):
402424
"""Return true if the object is an asynchronous generator function.

0 commit comments

Comments
 (0)