annotation-inspector
A Package inspried by typer's unique function inspection logic and turns configuring your own into a smaller system with a lot of boilerplate code removed out of the equation allowing for different instances or even multiple different translations of annotations to take place.
It can be used to build your own argument parser libaries that utilize function annotations but there is literally more to it than just that.
from dataclasses import dataclass
from typing import Annotated
from annotation_inspector import IGNORE, Inspector
@dataclass
class A:
value: int
@dataclass
class B:
value: str
def translate(name: str, origin: type, annotation, default):
# annotations that are not belonging to the provided system
# can also be translated the same as type origin.
# the system could easily be expanded upon as functools.partial
# or even a class method can easily lift the loads even more.
if issubclass(origin, str):
return B(name)
# returning Ignore means that this translated type should be dismissed.
return IGNORE
def func(a: Annotated[int, A(1)], b: str):
return b
def main():
translator = Inspector(A, B, translator=IGNORE)
# {'a': Param(name='a', default=<class 'inspect._empty'>, annotation=A(value=1)),
# 'b': Param(name='b', default=<class 'inspect._empty'>, annotation=IGNORE)}
print(translator.inspect(func))
# you can also translate missing annotations
translator2 = Inspector(A, B, translator=translate)
# {'a': Param(name='a', default=<class 'inspect._empty'>, annotation=A(value=1)),
# 'b': Param(name='b', default=<class 'inspect._empty'>, annotation=B(value='b'))}
print(translator2.inspect(func))
if __name__ == "__main__":
main()
Metadata
Release files for annotation-inspector 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| annotation_inspector-0.1.0.tar.gz | 6.9 kB | Without provenance | Details for annotation_inspector-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| annotation_inspector-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for annotation_inspector-0.1.0-py3-none-any.whl |
Total release size: 13.0 kB
Release files / annotation_inspector-0.1.0.tar.gz
| Download URL | annotation_inspector-0.1.0.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ec5e02f2cbd4eb0e08bc8270c73fef4be9e87b188cef21b7c1b72c19d921a05
|
|
BLAKE2b-256 checksum How to use checksums |
4526d470946fa353eb2b665a898ae4b29cf71b565c397a276a447eac89495bb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / annotation_inspector-0.1.0-py3-none-any.whl
| Download URL | annotation_inspector-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f63b5d70e4f211f35b597a21d2c88536c1b5af27a9fa935f4d28c7b87fb7c0a6
|
|
BLAKE2b-256 checksum How to use checksums |
075f4dedf1e5c1af06f256d6b84c739c8dcfe38ad9690e9809dbe73f93898773
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for annotation-inspector 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.