<s> from collections import defaultdict <EOL> class MultiDispatch ( object ) : <EOL> _fns = defaultdict ( dict ) <EOL> def __init__ ( self , fn ) : <EOL> self . fn = fn <EOL> self . __doc__ = fn . __doc__ <EOL> if fn . __name__ not in self . _fns [ fn . __module__ ] . keys ( ) : <EOL> self . _fns [ fn . __module__ ] [ fn . __name__ ] = { } <EOL> values = fn . __code__ . co_varnames <EOL> self . _fns [ fn . __module__ ] [ fn . __name__ ] [ values ] = fn <EOL> def is_fn ( self , v , args , kwargs ) : <EOL> """<STR_LIT>""" <EOL> com = list ( args ) + list ( kwargs . keys ( ) ) <EOL> if len ( com ) == len ( v ) : <EOL> return all ( [ kw in com for kw in kwargs . keys ( ) ] ) <EOL> return False <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> for i , fn in self . _fns [ self . fn . __module__ ] [ self . fn . __name__ ] . items ( ) : <EOL> if self . is_fn ( i , args , kwargs ) : <EOL> return fn ( * args , ** kwargs ) <EOL> raise TypeError ( "<STR_LIT>" ) </s>
