Registry / devops / get-annotations

get-annotations

JSON →
library0.1.2pypypi✓ verified 85d ago

A backport of Python 3.10's inspect.get_annotations() function, providing forward-compatible access to object annotations (function arguments, class attributes, etc.) for Python 3.6+. Version 0.1.2 is the latest; no recent releases.

pip install get-annotations
INSTALL
IMPORT
SIG · GET-ANNOTATIONS
G
get-annotations
devopspythonv0.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_annotations
from get_annotations import get_annotations
import get_annotations
Wrong: import get_annotations gives you the module, not the function. Right: from get_annotations import get_annotations

Replaces inspect.get_annotations() with a backport for older Python versions.

from get_annotations import get_annotations def func(a: int, b: str) -> bool: ... ann = get_annotations(func) print(ann) # prints {'a': int, 'b': str, 'return': bool}
Debug
Known issues
breakingThe library shadows the standard library's inspect.get_annotations on Python 3.10+; ensure you import from 'get_annotations' only when targeting Python <3.10.
fix
Use 'from get_annotations import get_annotations' only if sys.version_info < (3,10); otherwise use 'inspect.get_annotations'.
affects: >=3.10
gotchaCalling get_annotations on a built-in function (e.g., len) may raise TypeError or return None if annotations are not supported.
fix
Wrap call in try/except TypeError or check if object supports annotations via hasattr() before calling.
affects: all
gotchaThe function does not evaluate string annotations (PEP 563). If you rely on forward references, they remain as strings.
fix
Use typing.get_type_hints() if you need resolved annotations.
affects: all
Errors
Common errors & fixes
AttributeError: module 'get_annotations' has no attribute 'get_annotations'
Imported the module itself, not the function.
fix
Use 'from get_annotations import get_annotations'
TypeError: get_annotations() missing 1 required positional argument: 'obj'
Called get_annotations without any argument, or forgot the object.
fix
Call get_annotations(some_function_or_class)
Upgrade
Version history
0.1.2latest on PyPI · released Dec 27, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
get-annotations — pip install get-annotations · libregistry