Skip to content

Commit b27e227

Browse files
[3.13] gh-123242: Note that type.__annotations__ may not exist (GH-124557) (#124569)
Closes GH-123242. The real criterion is that the attribute does not exist on heap types, but I don't think we should discuss heap vs. static types in the language reference. (cherry picked from commit 99b23c6)
1 parent a079922 commit b27e227

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Doc/reference/datamodel.rst

+8
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,14 @@ Special attributes
10111011
collected during class body execution. For best practices on working
10121012
with :attr:`!__annotations__`, please see :ref:`annotations-howto`.
10131013

1014+
.. caution::
1015+
1016+
Accessing the :attr:`!__annotations__` attribute of a class
1017+
object directly may yield incorrect results in the presence of
1018+
metaclasses. In addition, the attribute may not exist for
1019+
some classes. Use :func:`inspect.get_annotations` to
1020+
retrieve class annotations safely.
1021+
10141022
* - .. attribute:: type.__type_params__
10151023
- A :class:`tuple` containing the :ref:`type parameters <type-params>` of
10161024
a :ref:`generic class <generic-classes>`.

0 commit comments

Comments
 (0)