mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-134370: Added clarification on instance annotations (#134387)
Instances of classes cannot have annotations, however sometimes they will erroneously have the __annotations__ attribute
This commit is contained in:
parent
d0eedfa10e
commit
bd4046f4f8
1 changed files with 6 additions and 1 deletions
|
|
@ -248,4 +248,9 @@ quirks by using :func:`annotationlib.get_annotations` on Python 3.14+ or
|
|||
:func:`inspect.get_annotations` on Python 3.10+. On earlier versions of
|
||||
Python, you can avoid these bugs by accessing the annotations from the
|
||||
class's :attr:`~type.__dict__`
|
||||
(e.g., ``cls.__dict__.get('__annotations__', None)``).
|
||||
(for example, ``cls.__dict__.get('__annotations__', None)``).
|
||||
|
||||
In some versions of Python, instances of classes may have an ``__annotations__``
|
||||
attribute. However, this is not supported functionality. If you need the
|
||||
annotations of an instance, you can use :func:`type` to access its class
|
||||
(for example, ``annotationlib.get_annotations(type(myinstance))`` on Python 3.14+).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue