diff options
Diffstat (limited to 'Doc/reference/datamodel.rst')
-rw-r--r-- | Doc/reference/datamodel.rst | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index b3096a9f0c3..4a099e81dac 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -262,6 +262,8 @@ Booleans (:class:`bool`) a string, the strings ``"False"`` or ``"True"`` are returned, respectively. +.. _datamodel-float: + :class:`numbers.Real` (:class:`float`) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1228,15 +1230,21 @@ Special attributes :attr:`__annotations__ attributes <object.__annotations__>`. For best practices on working with :attr:`~object.__annotations__`, - please see :mod:`annotationlib`. + please see :mod:`annotationlib`. Use + :func:`annotationlib.get_annotations` instead of accessing this + attribute directly. + + .. warning:: - .. caution:: + Accessing the :attr:`!__annotations__` attribute directly + on a class object may return annotations for the wrong class, specifically + in certain cases where the class, its base class, or a metaclass + is defined under ``from __future__ import annotations``. + See :pep:`749 <749#pep749-metaclasses>` for details. - Accessing the :attr:`!__annotations__` attribute of a class - object directly may yield incorrect results in the presence of - metaclasses. In addition, the attribute may not exist for - some classes. Use :func:`annotationlib.get_annotations` to - retrieve class annotations safely. + This attribute does not exist on certain builtin classes. On + user-defined classes without ``__annotations__``, it is an + empty dictionary. .. versionchanged:: 3.14 Annotations are now :ref:`lazily evaluated <lazy-evaluation>`. @@ -1247,13 +1255,6 @@ Special attributes if the class has no annotations. See also: :attr:`__annotate__ attributes <object.__annotate__>`. - .. caution:: - - Accessing the :attr:`!__annotate__` attribute of a class - object directly may yield incorrect results in the presence of - metaclasses. Use :func:`annotationlib.get_annotate_function` to - retrieve the annotate function safely. - .. versionadded:: 3.14 * - .. attribute:: type.__type_params__ @@ -3359,7 +3360,7 @@ left undefined. argument if the three-argument version of the built-in :func:`pow` function is to be supported. - .. versionchanged:: next + .. versionchanged:: 3.14 Three-argument :func:`pow` now try calling :meth:`~object.__rpow__` if necessary. Previously it was only called in two-argument :func:`!pow` and the binary |