Skip to main content

Tippo

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

Use the latest type annotation features in older versions of Python.

Motivation

When working with Python development for VFX pipelines we are often stuck with older Python versions for the runtime.

Tippo aims to bridge that gap since it allows us to use features such as static type checking (which could be performed by newer Python versions with support for MyPy during the testing phase) even though the code might be designed to run in Python 2.7, for example.

Installation

Tippo is available through pip:

pip install tippo

Usage

Instead of importing from typing and/or typing_extensions…

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

…just import directly from tippo:

>>> from tippo import TypeAlias, final

Generic Fixes

Tippo patches GenericMeta to fix known bugs for the Python 2.7 version of typing that were not addressed since it’s not officially supported anymore.

Generic class comparison:

>>> from tippo import Mapping
>>> assert Mapping[str, int] == Mapping[str, int]  # passes
>>> assert not (Mapping[str, int] != Mapping[str, int])  # passes

Subclassing a generic class with a __weakref__ slot:

>>> from weakref import ref
>>> from tippo import Generic, TypeVar
>>> T = TypeVar("T")
>>> class MyGeneric(Generic[T]):
...     __slots__ = ("__weakref__",)
...
>>> class SubClass(MyGeneric[T]):  # does not error out
...     __slots__ = ()
...
>>> instance = SubClass()
>>> instance_ref = ref(instance)

In order to maintain the same interface, GenericMeta points to type when imported from tippo in newer versions of Python.

Backports

Features from the latest versions of Python, such as TypeAlias, ClassVar, NewType, get_origin, and get_args.

>>> from tippo import Mapping, get_args, get_name
>>> mapping_type = Mapping[str, int]
>>> [get_name(a) for a in get_args(mapping_type)]
['str', 'int']

Commonly Used Protocols

Such as:

  • tippo.SupportsGetItem

  • tippo.SupportsGetSetItem

  • tippo.SupportsGetSetDeleteItem

  • tippo.SupportsKeysAndGetItem

>>> from tippo import SupportsGetItem
>>> class Foo(object):
...     def __getitem__(self, item):
...         # type: (str) -> int
...         return 3
...
>>> def get_stuff(bar):
...     # type: (SupportsGetItem[str, int]) -> int
...     return bar["stuff"]
...
>>> assert get_stuff(Foo()) == 3  # passes static type checking
>>> assert get_stuff({"stuff": 3}) == 3  # passes static type checking

Release files for tippo 4.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tippo 4.1.1
File Size Uploaded
tippo-4.1.1.tar.gz 15.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tippo 4.1.1
File Interpreter ABI Platform
tippo-4.1.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 23.7 kB

Release files / tippo-4.1.1.tar.gz

Download URL tippo-4.1.1.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1267825bccaa4c38d285d04b8f89ad82686cd34dece22a0f4b40000c959de78a
BLAKE2b-256 checksum
How to use checksums
49ecb9fbe6569b331db291de44f81a9c66d0a696fbc8f65723bc5b32e4687276
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Release files / tippo-4.1.1-py2.py3-none-any.whl

Download URL tippo-4.1.1-py2.py3-none-any.whl
Size 8.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e770b15c471c39720c49a7fd8cd1109466ff91a338302582cbcc5ec35a772e32
BLAKE2b-256 checksum
How to use checksums
395332425bf32e40046a2b9c97e2aa11fcbe6037bcab5bb3190b845ae3d56853
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Release history Release notifications | RSS feed

This release

4.1.1 This release

2 release files

4.1.0

2 release files

4.0.4

2 release files

4.0.3

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.9.0

2 release files

3.8.0

2 release files

3.7.0

2 release files

3.6.0

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.7.0

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page