]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-43817: Add inspect.get_annotations(). (#25522)
authorlarryhastings <larry@hastings.org>
Fri, 30 Apr 2021 04:16:28 +0000 (21:16 -0700)
committerGitHub <noreply@github.com>
Fri, 30 Apr 2021 04:16:28 +0000 (21:16 -0700)
commit74613a46fc79cacc88d3eae4105b12691cd4ba20
treee4bb45c84127a124ac969aa06e0946798a7e5bba
parenta62e424de0c394cda178a8d934d06f0559b5e28d
bpo-43817: Add inspect.get_annotations(). (#25522)

Add inspect.get_annotations, which safely computes the annotations defined on an object.  It works around the quirks of accessing the annotations from various types of objects, and makes very few assumptions about the object passed in. inspect.get_annotations can also correctly un-stringize stringized annotations.

inspect.signature, inspect.from_callable, and inspect.from_function now call inspect.get_annotations to retrieve annotations.  This means inspect.signature and inspect.from_callable can now un-stringize stringized annotations, too.
Doc/library/inspect.rst
Lib/inspect.py
Lib/test/inspect_stock_annotations.py [new file with mode: 0644]
Lib/test/inspect_stringized_annotations.py [new file with mode: 0644]
Lib/test/inspect_stringized_annotations_2.py [new file with mode: 0644]
Lib/test/test_inspect.py
Misc/NEWS.d/next/Library/2021-04-22-04-12-13.bpo-43817.FQ-XlH.rst [new file with mode: 0644]