class_docstr: Patches an attribute of an object for the duration of this context manager.
  Similar to unittest.mock.patch,
  but works also for properties that are not present in the original class
  
  >>> class MyObj:
  ...     attr = 'original'
  >>> my_obj = MyObj()
  >>> with PatchedAttribute(my_obj, 'attr', 'patched'):
  ...     print(my_obj.attr)
  patched
  >>> print(my_obj.attr)
  original
  >>> with PatchedAttribute(my_obj, 'new_attr', 'new_patched'):
  ...     print(my_obj.new_attr)
  new_patched
  >>> assert not hasattr(my_obj, 'new_attr')
class_docstr_tok: ["Patches","an","attribute","of","an","object","for","the","duration","of","this","context","manager",".","Similar","to","unittest.mock.patch",",","but","works","also","for","properties","that","are","not","present","in","the","original","class",">",">",">","class","MyObj",":","...","attr","=","'original'",">",">",">","my_obj","=","MyObj","(",")",">",">",">","with","PatchedAttribute","(","my_obj",",","'attr","'",",","'patched","'",")",":","...","print","(","my_obj.attr",")","patched",">",">",">","print","(","my_obj.attr",")","original",">",">",">","with","PatchedAttribute","(","my_obj",",","'new_attr","'",",","'new_patched","'",")",":","...","print","(","my_obj.new_attr",")","new_patched",">",">",">","assert","not","hasattr","(","my_obj",",","'new_attr","'",")"]
code: def __exit__(self, exc_type, exc_val, exc_tb):
      if self.original_exists:
          setattr(self.obj, self.attribute, self.original_value)
      else:
          delattr(self.obj, self.attribute)
  
imports: import logging
  import os
  import pickle
  import random
  import zipfile
  from typing import Any
  import numpy
  import openai
  import psutil
  import torch
label_desc: Use image node_id 3 for calling the PatchedAttribute obj's underlying member method code with example usage: obj.__exit__(exc_type, exc_val, exc_tb) without return types