Ejemplo n.º 1
0
 def __new__(cls, wrapped):
     assert cls is ErrorBag
     if is_error_class(wrapped):
         if _ABC_NICE_WITH_ERRORS:
             self = wrapped
         else:
             self = super(ErrorBag, cls).__new__(cls)
             self.wrapped = wrapped
         name = wrapped.__name__
         if not hasattr(cls, name):
             with _bag_assign.enter():
                 # to avoid direct assigning block
                 setattr(cls, name, self)
             return wrapped
         else:
             raise RuntimeError('Error "{}" already adopted.'.format(name))
     else:
         from xoutil.names import simple_name
         msg = 'Parameter `wrapped` must be an exception class, not "{}".'
         raise TypeError(msg.format(simple_name(wrapped)))