https://github.com/python/cpython/commit/7e7391810fa1e8e378d6073c57914bc79d4e9295 commit: 7e7391810fa1e8e378d6073c57914bc79d4e9295 branch: 3.14 author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com> committer: JelleZijlstra <jelle.zijls...@gmail.com> date: 2025-05-22T13:52:37Z summary:
[3.14] gh-134370: Added clarification on instance annotations (GH-134387) (#134509) gh-134370: Added clarification on instance annotations (GH-134387) Instances of classes cannot have annotations, however sometimes they will erroneously have the __annotations__ attribute (cherry picked from commit bd4046f4f869039a1a2ebe2d1d18bfbc2a2951b6) Co-authored-by: Alex Kautz <a...@takemobi.com> files: M Doc/howto/annotations.rst diff --git a/Doc/howto/annotations.rst b/Doc/howto/annotations.rst index 78f3704ba5d000..d7deb6c6bc1768 100644 --- a/Doc/howto/annotations.rst +++ b/Doc/howto/annotations.rst @@ -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+). _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: arch...@mail-archive.com