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)
Metadata
Release files for tsukkomi 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tsukkomi-0.0.6.tar.gz | 4.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tsukkomi-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.2 kB
Release files / tsukkomi-0.0.6.tar.gz
| Download URL | tsukkomi-0.0.6.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52ea2c4df408226c8827d41c8e06b1e025e293a1495b52a522c61f77e4c78b29
|
|
BLAKE2b-256 checksum How to use checksums |
9bfa9c60201bb422fb7159f23fcc35458b127f17367c3599f36a55f0d666f300
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / tsukkomi-0.0.6-py3-none-any.whl
| Download URL | tsukkomi-0.0.6-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f549db3a0f0a3bacaf55a01981671c7640693e63eaaab51c63aacf4980e6dab5
|
|
BLAKE2b-256 checksum How to use checksums |
ba2b6faa5d09d7dd516a7c452a01459bfc297c7ed9155bf0fb2f4b521ef50112
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |