为python类型创建tsukkomi
tsukkomi的Python项目详细描述
恙虫
对python类型执行tsukkomi。
什么是春宫?
在西方的喜剧双重唱中,tsukkomi是一个日语单词,意思是直男。 文化。当异性恋者对伴侣的荒唐行为做出反应时,tsukkomi 会对不正确的类型做出反应。
如何使用筑波米?
tsukkomi从typing获取类型提示。编写带有注释的代码, 用tsukkomi.typed.typechecked装饰所有可调用对象。 仅供参考不支持泛型类型,请参见tsukkomi dosen’t support generic 细节部分。
fromtypingimportSequencefromtsukkomi.typedimporttypechecked@typecheckeddefgreeting(name:str)->str:returnnamegreeting('a')# it is okgreeting(1)# this will raise `TypeError`
Tsukkomi Dosen不支持泛型
tsukkomi dosen不支持generic类型检查,已包含类型 继承了一个泛型类型,如typing.sequence,typing.mutable等。 下面的示例代码可以由tsukkomi.typed.typechecked传递。
importtypingfromtsukkomi.typedimporttypecheckedT=typing.TypeVar('T')classBoke(typing.Generic[T]):@typecheckeddefstupid(self,word:T)->T:returntype(word)@typecheckeddefcorrection(self,words:Sequence[T])->T:returnrandom.sample(words,1)[0]@typecheckeddefboke_and_tsukkomi(stupid_words:Sequence[str],correction:Sequence[str])->bool:returnany(s==cfors,cinzip(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]))
变更日志
0.0.5-2016-05-19
修改
- 将none解释为类型(none)
修改
- 将none解释为类型(none)