@contextlib.contextmanager
def hide_attrs(obj, *attrs):
 obj_vals = (obj.__dict__ if (obj is not None) else {})
 saved_vals = {}
 for name in attrs:
  saved_vals[name] = obj_vals.pop(name, _marker)
 try:
  (yield)
 finally:
  for name in attrs:
   saved_val = saved_vals[name]
   if (saved_val is not _marker):
    obj_vals[name] = saved_val
   elif (name in obj_vals):
    del obj_vals[name]

@ contextlib . contextmanager def hide_attrs ( obj , * attrs ) : obj_vals = ( obj . __dict__ if ( obj is not None ) else { } ) saved_vals = { } for name in attrs : saved_vals [ name ] = obj_vals . pop ( name , _marker ) try : ( yield ) finally : for name in attrs : saved_val = saved_vals [ name ] if ( saved_val is not _marker ) : obj_vals [ name ] = saved_val elif ( name in obj_vals ) : del obj_vals [ name ]
temporarily delete object attrs and restore afterward .