Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nrbnlulu/typingref
Introspect Python type annotation
https://github.com/nrbnlulu/typingref
Last synced: about 2 months ago
JSON representation
Introspect Python type annotation
- Host: GitHub
- URL: https://github.com/nrbnlulu/typingref
- Owner: nrbnlulu
- License: mit
- Created: 2023-03-28T18:01:23.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-21T16:23:56.000Z (about 1 year ago)
- Last Synced: 2024-04-24T14:10:36.928Z (9 months ago)
- Language: Python
- Homepage: https://nrbnlulu.github.io/typingref/
- Size: 787 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
![header.png](docs%2Fassets%2Fheader.png)
*Introspect Python type annotation, with ease.*
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/nrbnlulu/typingref/tests.yml?style=for-the-badge)
[![PyPI](https://img.shields.io/pypi/v/typingref?style=for-the-badge)
](https://pypi.org/project/typingref/)
[![Codecov](https://img.shields.io/codecov/c/github/nrbnlulu/typingref?style=for-the-badge)
](https://app.codecov.io/gh/nrbnlulu/typingref)Modern Python libraries often use type annotations,
this library is intended to help "de/serialize" Python type hints to something
you can work with.### Sample Usage:
```python
from typingref import TypeHinter
from typing import Unionclass MyType:
...def foo(p: Union[int, str, float]) -> MyType:
...p_type = TypeHinter.from_annotation(foo.__annotations__['p'])
if p_type.is_union():
for t in p_type.of_type:
...assert Union[int, str, float] == p_type.as_annotation()
```