def simplegeneric(func):
 registry = {}
 def wrapper(*args, **kw):
  ob = args[0]
  try:
   cls = ob.__class__
  except AttributeError:
   cls = type(ob)
  try:
   mro = cls.__mro__
  except AttributeError:
   try:
    class cls(cls, object, ):
     pass
    mro = cls.__mro__[1:]
   except TypeError:
    mro = (object,)
  for t in mro:
   if (t in registry):
    return registry[t](*args, **kw)
  else:
   return func(*args, **kw)
 try:
  wrapper.__name__ = func.__name__
 except (TypeError, AttributeError):
  pass
 def register(typ, func=None):
  if (func is None):
   return (lambda f: register(typ, f))
  registry[typ] = func
  return func
 wrapper.__dict__ = func.__dict__
 wrapper.__doc__ = func.__doc__
 wrapper.register = register
 return wrapper

def simplegeneric ( func ) : registry = { } def wrapper ( * args , ** kw ) : ob = args [ 0 ] try : cls = ob . __class__ except AttributeError : cls = type ( ob ) try : mro = cls . __mro__ except AttributeError : try : class cls ( cls , object , ) : pass mro = cls . __mro__ [ 1 : ] except TypeError : mro = ( object , ) for t in mro : if ( t in registry ) : return registry [ t ] ( * args , ** kw ) else : return func ( * args , ** kw ) try : wrapper . __name__ = func . __name__ except ( TypeError , AttributeError ) : pass def register ( typ , func = None ) : if ( func is None ) : return ( lambda f : register ( typ , f ) ) registry [ typ ] = func return func wrapper . __dict__ = func . __dict__ wrapper . __doc__ = func . __doc__ wrapper . register = register return wrapper
make a trivial single-dispatch generic function .