Add fallback decorators -- otherwise

This commit is contained in:
Andrey Popp 2011-06-26 22:23:57 +04:00
parent 024c429af1
commit aa6407ff37

View File

@ -71,7 +71,7 @@ class FunctionDispatcher(object):
self.registry = Registry(*axis)
def check_rule(self, rule, *argtypes):
# Check if we have the right number of parametrized types
# Check if we have the right number of parametrized types
if len(argtypes) != self.params_arity:
raise TypeError("Wrong number of type parameters.")
@ -106,6 +106,13 @@ class FunctionDispatcher(object):
return self
return register_rule
@property
def otherwise(self):
def register_rule(func):
self.register_rule(func, [object]*self.params_arity)
return self
return register_rule
def override(self, *argtypes):
def override_rule(func):
self.override_rule(func, *argtypes)
@ -158,6 +165,13 @@ class MethodDispatcher(FunctionDispatcher):
override = when
@property
def otherwise(self):
def make_declaration(func):
self.register_unbound_rule(func, [object]*self.params_arity)
return self
return make_declaration
def arity(argspec):
""" Determinal positional arity of argspec."""