Skip to content

Commit 7ce138f

Browse files
[3.12] gh-123242: Note that type.__annotations__ may not exist (GH-124557) (#124562)
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 d2068c6 commit 7ce138f

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
@@ -1009,6 +1009,14 @@ Special attributes
10091009
collected during class body execution. For best practices on working
10101010
with :attr:`!__annotations__`, please see :ref:`annotations-howto`.
10111011

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

0 commit comments

Comments
 (0)