Skip to content
(This project is abandoned. We recommend you to use typeguard instead.)
Python Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
tests
tsukkomi
.gitignore
.travis.yml
LICENSE
README.rst
pre-commit
setup.py
tox.ini

README.rst

Warning

This project is abandoned.

We recommend you to use typeguard instead. It has been well maintained, and provides the mostly same API to tsukkomi so that typeguard module is drop-in replacement of tsukkomi.typed module.


tsukkomi

do tsukkomi for python types.

What is tsukkomi?

tsukkomi is a japanese word means straight man in the comedy duos of western culture. As straight man react partner's ridiculous behaviors, tsukkomi will react incorrect types.

How to use tsukkomi?

tsukkomi take type hints from typing. write code with annotation, decorate all callable objects with tsukkomi.typed.typechecked. FYI generic types are not supported, see tsukkomi dosen't support generic section for the detail.

from typing import Sequence

from tsukkomi.typed import typechecked

@typechecked
def greeting(name: str) -> str:
    return name

greeting('a') # it is ok
greeting(1) # this will raise `TypeError`

tsukkomi dosen't support generic

tsukkomi dosen't support generic type checking, includes types already inherited a generic type like typing.Sequence, typing.Mutable and etc. following example codes can be passed by tsukkomi.typed.typechecked.

import typing

from tsukkomi.typed import typechecked


T = typing.TypeVar('T')


class Boke(typing.Generic[T]):

    @typechecked
    def stupid(self, word: T) -> T:
        return type(word)

    @typechecked
    def correction(self, words: Sequence[T]) -> T:
        return random.sample(words, 1)[0]


@typechecked
def boke_and_tsukkomi(stupid_words: Sequence[str],
                      correction: Sequence[str]) -> bool:
    return any(s == c for s, c in zip(stupid_words, correction)))


boke = Boke[str]()
print(boke.stupid('hello world'))
print(boke.correction([1, 2, 3]))
print(boke_and_tsukkomi([1, 2], [1.0, 2.0]))

Changelogs

0.0.5 --- 2016-05-19

Modified
  • Interpret None as type(None)
You can’t perform that action at this time.