def find_nearest_pickleable_exception(exc):
 cls = exc.__class__
 getmro_ = getattr(cls, 'mro', None)
 if (not getmro_):
  if (not getattr(cls, '__bases__', ())):
   return
  getmro_ = (lambda : inspect.getmro(cls))
 for supercls in getmro_():
  if (supercls in unwanted_base_classes):
   return
  try:
   exc_args = getattr(exc, 'args', [])
   superexc = supercls(*exc_args)
   pickle.dumps(superexc)
  except:
   pass
  else:
   return superexc

def find_nearest_pickleable_exception ( exc ) : cls = exc . __class__ getmro_ = getattr ( cls , 'mro' , None ) if ( not getmro_ ) : if ( not getattr ( cls , '__bases__' , ( ) ) ) : return getmro_ = ( lambda : inspect . getmro ( cls ) ) for supercls in getmro_ ( ) : if ( supercls in unwanted_base_classes ) : return try : exc_args = getattr ( exc , 'args' , [ ] ) superexc = supercls ( * exc_args ) pickle . dumps ( superexc ) except : pass else : return superexc
with an exception instance .