Skip to main content

Cleaner and forwards compatible way to use typing features

Project description

https://github.com/brunonicko/tippo/workflows/MyPy/badge.svg https://github.com/brunonicko/tippo/workflows/Lint/badge.svg https://github.com/brunonicko/tippo/workflows/Tests/badge.svg https://readthedocs.org/projects/tippo/badge/?version=stable https://img.shields.io/github/license/brunonicko/tippo?color=light-green https://static.pepy.tech/personalized-badge/tippo?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads https://img.shields.io/pypi/pyversions/tippo?color=light-green&style=flat

Overview

Tippo provides a cleaner and forwards compatible way to use features from the typing and typing_extension modules on python 3.7+.

Example

Instead of using an ugly try block for forwards compatibility…

>>> try:
...     from typing import Annotated
... except ImportError:
...     from typing_extensions import Annotated
...
>>> try:
...     from typing import final
... except ImportError:
...     from typing_extensions import final
...

…just import directly from tippo!

>>> from tippo import Annotated, final

Generic Weak Structures

Tippo also implements generic versions of weak data structures that work with older python versions’ type annotations (3.7) without the need to defer their evaluation:

>>> from tippo import Any, ReferenceType, WeakSet, WeakKeyDictionary, WeakValueDictionary
>>> class X:
...     pass
>>> weak_ref: ReferenceType[X]
>>> weak_set: WeakSet[X]
>>> weak_key_dict: WeakKeyDictionary[X, Any]
>>> weak_value_dict: WeakValueDictionary[Any, X]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tippo-0.1.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

tippo-0.1.0-py2.py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page