Skip to content

Commit 59749a3

Browse files
committed
Added clarification on instances annotations
Instances of classes cannot have annotations, however sometimes they will erroneously have the __annotations__ attribute
1 parent 91e6a58 commit 59749a3

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Doc/glossary.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Glossary
5252
can be retrieved by calling :func:`annotationlib.get_annotations`
5353
on modules, classes, and functions, respectively.
5454

55+
Note that an *instance* of a :term:`class` cannot be annotated.
56+
5557
See :term:`variable annotation`, :term:`function annotation`, :pep:`484`,
5658
:pep:`526`, and :pep:`649`, which describe this functionality.
5759
Also see :ref:`annotations-howto`

Doc/howto/annotations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,8 @@ quirks by using :func:`annotationlib.get_annotations` on Python 3.14+ or
249249
Python, you can avoid these bugs by accessing the annotations from the
250250
class's :attr:`~type.__dict__`
251251
(e.g., ``cls.__dict__.get('__annotations__', None)``).
252+
253+
In some versions of Python, instances of classes may have an ``__annotations__``
254+
attribute. This is not supported functionality, so the best practice is to always
255+
interact with the ``__annotations__`` attribute of an instance's type. For example
256+
``type(myinstance).__annotations__``.

0 commit comments

Comments
 (0)