Skip to main content

make tsukkomi for python types

Project description

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]))

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

tsukkomi-0.0.4.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

tsukkomi-0.0.4-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file tsukkomi-0.0.4.tar.gz.

File metadata

  • Download URL: tsukkomi-0.0.4.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tsukkomi-0.0.4.tar.gz
Algorithm Hash digest
SHA256 f778d561a7bb58df5e35463e71f3ae504be06e4af77e173ad1f92bf343918c35
MD5 41fdd0a7d0f9042527a5c7835646dc4c
BLAKE2b-256 4eba1d466e6940d32d1189a76806ac2882c413a0a40352188cb30152080887df

See more details on using hashes here.

File details

Details for the file tsukkomi-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for tsukkomi-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c974526788915b4103c7beb24d3ed93ff85c8b43df96629724dd9d1ee0a74a00
MD5 2a2cd934294e245f98b297132aeb75c0
BLAKE2b-256 132199d5f3ca08f444dd4ccf8ff9cdf8e9000a41666f0ed9685b19a097f1fc8b

See more details on using hashes here.

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