Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into codegen-labels-cont
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Aug 10, 2022
2 parents cf4740b + 325ae93 commit bb16973
Show file tree
Hide file tree
Showing 128 changed files with 2,267 additions and 2,551 deletions.
9 changes: 9 additions & 0 deletions Doc/c-api/call.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ This bears repeating:
A class supporting vectorcall **must** also implement
:c:member:`~PyTypeObject.tp_call` with the same semantics.

.. versionchanged:: 3.12

The :const:`Py_TPFLAGS_HAVE_VECTORCALL` flag is now removed from a class
when the class's :py:meth:`~object.__call__` method is reassigned.
(This internally sets :c:member:`~PyTypeObject.tp_call` only, and thus
may make it behave differently than the vectorcall function.)
In earlier Python versions, vectorcall should only be used with
:const:`immutable <Py_TPFLAGS_IMMUTABLETYPE>` or static types.

A class should not implement vectorcall if that would be slower
than *tp_call*. For example, if the callee needs to convert
the arguments to an args tuple and kwargs dict anyway, then there is no point
Expand Down
18 changes: 18 additions & 0 deletions Doc/c-api/object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ Object Protocol
A generic implementation for the getter of a ``__dict__`` descriptor. It
creates the dictionary if necessary.
This function may also be called to get the :py:attr:`~object.__dict__`
of the object *o*. Pass ``NULL`` for *context* when calling it.
Since this function may need to allocate memory for the
dictionary, it may be more efficient to call :c:func:`PyObject_GetAttr`
when accessing an attribute on the object.
On failure, returns ``NULL`` with an exception set.
.. versionadded:: 3.3
Expand All @@ -137,6 +145,16 @@ Object Protocol
.. versionadded:: 3.3
.. c:function:: PyObject** _PyObject_GetDictPtr(PyObject *obj)
Return a pointer to :py:attr:`~object.__dict__` of the object *obj*.
If there is no ``__dict__``, return ``NULL`` without setting an exception.
This function may need to allocate memory for the
dictionary, so it may be more efficient to call :c:func:`PyObject_GetAttr`
when accessing an attribute on the object.
.. c:function:: PyObject* PyObject_RichCompare(PyObject *o1, PyObject *o2, int opid)
Compare the values of *o1* and *o2* using the operation specified by *opid*,
Expand Down
65 changes: 36 additions & 29 deletions Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Quick Reference
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
| [:c:member:`~PyTypeObject.tp_cache`] | :c:type:`PyObject` * | | | | |
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
| [:c:member:`~PyTypeObject.tp_subclasses`] | :c:type:`PyObject` * | __subclasses__ | | | |
| [:c:member:`~PyTypeObject.tp_subclasses`] | void * | __subclasses__ | | | |
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
| [:c:member:`~PyTypeObject.tp_weaklist`] | :c:type:`PyObject` * | | | | |
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
Expand Down Expand Up @@ -720,29 +720,29 @@ and :c:type:`PyType_Type` effectively act as defaults.)
with the *vectorcallfunc* function.
This can be done by setting *tp_call* to :c:func:`PyVectorcall_Call`.

.. warning::

It is not recommended for :ref:`mutable heap types <heap-types>` to implement
the vectorcall protocol.
When a user sets :attr:`__call__` in Python code, only *tp_call* is updated,
likely making it inconsistent with the vectorcall function.

.. versionchanged:: 3.8

Before version 3.8, this slot was named ``tp_print``.
In Python 2.x, it was used for printing to a file.
In Python 3.0 to 3.7, it was unused.

.. versionchanged:: 3.12

Before version 3.12, it was not recommended for
:ref:`mutable heap types <heap-types>` to implement the vectorcall
protocol.
When a user sets :attr:`~type.__call__` in Python code, only *tp_call* is
updated, likely making it inconsistent with the vectorcall function.
Since 3.12, setting ``__call__`` will disable vectorcall optimization
by clearing the :const:`Py_TPFLAGS_HAVE_VECTORCALL` flag.

**Inheritance:**

This field is always inherited.
However, the :const:`Py_TPFLAGS_HAVE_VECTORCALL` flag is not
always inherited. If it's not, then the subclass won't use
always inherited. If it's not set, then the subclass won't use
:ref:`vectorcall <vectorcall>`, except when
:c:func:`PyVectorcall_Call` is explicitly called.
This is in particular the case for types without the
:const:`Py_TPFLAGS_IMMUTABLETYPE` flag set (including subclasses defined in
Python).


.. c:member:: getattrfunc PyTypeObject.tp_getattr
Expand Down Expand Up @@ -1178,12 +1178,18 @@ and :c:type:`PyType_Type` effectively act as defaults.)

**Inheritance:**

This bit is inherited for types with the
:const:`Py_TPFLAGS_IMMUTABLETYPE` flag set, if
:c:member:`~PyTypeObject.tp_call` is also inherited.
This bit is inherited if :c:member:`~PyTypeObject.tp_call` is also
inherited.

.. versionadded:: 3.9

.. versionchanged:: 3.12

This flag is now removed from a class when the class's
:py:meth:`~object.__call__` method is reassigned.

This flag can now be inherited by mutable classes.

.. data:: Py_TPFLAGS_IMMUTABLETYPE

This bit is set for type objects that are immutable: type attributes cannot be set nor deleted.
Expand Down Expand Up @@ -1709,18 +1715,11 @@ and :c:type:`PyType_Type` effectively act as defaults.)
:c:member:`~PyTypeObject.tp_dictoffset` should be set to ``-4`` to indicate that the dictionary is
at the very end of the structure.

The real dictionary offset in an instance can be computed from a negative
:c:member:`~PyTypeObject.tp_dictoffset` as follows::

dictoffset = tp_basicsize + abs(ob_size)*tp_itemsize + tp_dictoffset
if dictoffset is not aligned on sizeof(void*):
round up to sizeof(void*)

where :c:member:`~PyTypeObject.tp_basicsize`, :c:member:`~PyTypeObject.tp_itemsize` and :c:member:`~PyTypeObject.tp_dictoffset` are
taken from the type object, and :attr:`ob_size` is taken from the instance. The
absolute value is taken because ints use the sign of :attr:`ob_size` to
store the sign of the number. (There's never a need to do this calculation
yourself; it is done for you by :c:func:`_PyObject_GetDictPtr`.)
The :c:member:`~PyTypeObject.tp_dictoffset` should be regarded as write-only.
To get the pointer to the dictionary call :c:func:`PyObject_GenericGetDict`.
Calling :c:func:`PyObject_GenericGetDict` may need to allocate memory for the
dictionary, so it is may be more efficient to call :c:func:`PyObject_GetAttr`
when accessing an attribute on the object.

**Inheritance:**

Expand Down Expand Up @@ -1928,9 +1927,17 @@ and :c:type:`PyType_Type` effectively act as defaults.)
This field is not inherited.


.. c:member:: PyObject* PyTypeObject.tp_subclasses
.. c:member:: void* PyTypeObject.tp_subclasses
A collection of subclasses. Internal use only. May be an invalid pointer.

To get a list of subclasses, call the Python method
:py:meth:`~class.__subclasses__`.

.. versionchanged:: 3.12

List of weak references to subclasses. Internal use only.
For some types, this field does not hold a valid :c:expr:`PyObject*`.
The type was changed to :c:expr:`void*` to indicate this.

**Inheritance:**

Expand Down
8 changes: 5 additions & 3 deletions Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,6 @@ APIs:
| | | :c:func:`PyObject_Repr`. |
+-------------------+---------------------+----------------------------------+
An unrecognized format character causes all the rest of the format string to be
copied as-is to the result string, and any extra arguments discarded.
.. note::
The width formatter unit is number of characters rather than bytes.
The precision formatter unit is number of bytes for ``"%s"`` and
Expand All @@ -500,6 +497,11 @@ APIs:
Support width and precision formatter for ``"%s"``, ``"%A"``, ``"%U"``,
``"%V"``, ``"%S"``, ``"%R"`` added.
.. versionchanged:: 3.12
An unrecognized format character now sets a :exc:`SystemError`.
In previous versions it caused all the rest of the format string to be
copied as-is to the result string, and any extra arguments discarded.
.. c:function:: PyObject* PyUnicode_FromFormatV(const char *format, va_list vargs)
Expand Down
3 changes: 3 additions & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ Creating Futures and Tasks

.. method:: loop.create_task(coro, *, name=None, context=None)

Schedule the execution of a :ref:`coroutine`.
Schedule the execution of :ref:`coroutine <coroutine>` *coro*.
Return a :class:`Task` object.

Third-party event loops can use their own subclass of :class:`Task`
Expand Down
38 changes: 19 additions & 19 deletions Doc/library/bisect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@

This module provides support for maintaining a list in sorted order without
having to sort the list after each insertion. For long lists of items with
expensive comparison operations, this can be an improvement over the more common
approach. The module is called :mod:`bisect` because it uses a basic bisection
algorithm to do its work. The source code may be most useful as a working
example of the algorithm (the boundary conditions are already right!).
expensive comparison operations, this can be an improvement over
linear searches or frequent resorting.

The module is called :mod:`bisect` because it uses a basic bisection
algorithm to do its work. Unlike other bisection tools that search for a
specific value, the functions in this module are designed to locate an
insertion point. Accordingly, the functions never call an :meth:`__eq__`
method to determine whether a value has been found. Instead, the
functions only call the :meth:`__lt__` method and will return an insertion
point between values in an array.

The following functions are provided:

Expand All @@ -30,16 +36,17 @@ The following functions are provided:
any existing entries. The return value is suitable for use as the first
parameter to ``list.insert()`` assuming that *a* is already sorted.

The returned insertion point *i* partitions the array *a* into two halves so
that ``all(val < x for val in a[lo : i])`` for the left side and
``all(val >= x for val in a[i : hi])`` for the right side.
The returned insertion point *ip* partitions the array *a* into two
slices such that ``all(elem < x for elem in a[lo : ip])`` is true for the
left slice and ``all(elem >= x for elem in a[ip : hi])`` is true for the
right slice.

*key* specifies a :term:`key function` of one argument that is used to
extract a comparison key from each element in the array. To support
searching complex records, the key function is not applied to the *x* value.

If *key* is ``None``, the elements are compared directly with no
intervening function call.
If *key* is ``None``, the elements are compared directly and
no key function is called.

.. versionchanged:: 3.10
Added the *key* parameter.
Expand All @@ -51,16 +58,9 @@ The following functions are provided:
Similar to :func:`bisect_left`, but returns an insertion point which comes
after (to the right of) any existing entries of *x* in *a*.

The returned insertion point *i* partitions the array *a* into two halves so
that ``all(val <= x for val in a[lo : i])`` for the left side and
``all(val > x for val in a[i : hi])`` for the right side.

*key* specifies a :term:`key function` of one argument that is used to
extract a comparison key from each element in the array. To support
searching complex records, the key function is not applied to the *x* value.

If *key* is ``None``, the elements are compared directly with no
intervening function call.
The returned insertion point *ip* partitions the array *a* into two slices
such that ``all(elem <= x for elem in a[lo : ip])`` is true for the left slice and
``all(elem > x for elem in a[ip : hi])`` is true for the right slice.

.. versionchanged:: 3.10
Added the *key* parameter.
Expand Down
18 changes: 18 additions & 0 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,24 @@ The Python compiler currently generates the following bytecode instructions.
.. versionadded:: 3.11


.. opcode:: CACHE

Rather than being an actual instruction, this opcode is used to mark extra
space for the interpreter to cache useful data directly in the bytecode
itself. It is automatically hidden by all ``dis`` utilities, but can be
viewed with ``show_caches=True``.

Logically, this space is part of the preceding instruction. Many opcodes
expect to be followed by an exact number of caches, and will instruct the
interpreter to skip over them at runtime.

Populated caches can look like arbitrary instructions, so great care should
be taken when reading or modifying raw, adaptive bytecode containing
quickened data.

.. versionadded:: 3.11


**Unary operations**

Unary operations take the top of the stack, apply the operation, and push the
Expand Down
3 changes: 0 additions & 3 deletions Doc/library/email.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,3 @@ Legacy API:
Module :mod:`mailbox`
Tools for creating, reading, and managing collections of messages on disk
using a variety standard formats.

Module :mod:`smtpd`
SMTP server framework (primarily useful for testing)
2 changes: 1 addition & 1 deletion Doc/library/functools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ The :mod:`functools` module defines the following functions:
tool for programs being converted from Python 2 which supported the use of
comparison functions.

A comparison function is any callable that accept two arguments, compares them,
A comparison function is any callable that accepts two arguments, compares them,
and returns a negative number for less-than, zero for equality, or a positive
number for greater-than. A key function is a callable that accepts one
argument and returns another value to be used as the sort key.
Expand Down
Loading

0 comments on commit bb16973

Please sign in to comment.