更细粒度的functools.singledispatch
allot的Python项目详细描述
类似于functools.singledispatch,但允许为每个类注册多个函数。
如果注册的函数在检查后决定无法处理该值,则它可以放弃并让其他函数试试运气:
fromallotimportallot,Pass@allotdeff(obj):return'object'@f.register(int)deff_small_integer(obj):ifobj>10:returnPassreturn'small integer'assertf('a string')=='object'assertf(3)=='small integer'assertf(10)=='object'