Add fallback decorators -- otherwise
This commit is contained in:
parent
024c429af1
commit
aa6407ff37
@ -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."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user