Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bd4046f

Browse filesBrowse files
authored
gh-134370: Added clarification on instance annotations (#134387)
Instances of classes cannot have annotations, however sometimes they will erroneously have the __annotations__ attribute
1 parent d0eedfa commit bd4046f
Copy full SHA for bd4046f

File tree

Expand file treeCollapse file tree

1 file changed

+6
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-1
lines changed

‎Doc/howto/annotations.rst

Copy file name to clipboardExpand all lines: Doc/howto/annotations.rst
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,9 @@ quirks by using :func:`annotationlib.get_annotations` on Python 3.14+ or
248248
:func:`inspect.get_annotations` on Python 3.10+. On earlier versions of
249249
Python, you can avoid these bugs by accessing the annotations from the
250250
class's :attr:`~type.__dict__`
251-
(e.g., ``cls.__dict__.get('__annotations__', None)``).
251+
(for example, ``cls.__dict__.get('__annotations__', None)``).
252+
253+
In some versions of Python, instances of classes may have an ``__annotations__``
254+
attribute. However, this is not supported functionality. If you need the
255+
annotations of an instance, you can use :func:`type` to access its class
256+
(for example, ``annotationlib.get_annotations(type(myinstance))`` on Python 3.14+).

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.