class_docstr: Base class for method decorators which can be used to replace methods pass to replace_method() with wrapped versions.
docstr: Add the (name,self.replace_method) pair to the list named by replace_list_name in `owner`, creating the list and
  replacing the constructor of `owner` if necessary. The replaced constructor will call the old one then do the
  replacing operation of substituting, for each (name,self.replace_method) pair, the named method with the returned
  value from self.replace_method.
docstr_tok: ["Add","the","(","name",",","self.replace_method",")","pair","to","the","list","named","by","replace_list_name","in","`","owner","`",",","creating","the","list","and","replacing","the","constructor","of","`","owner","`","if","necessary",".","The","replaced","constructor","will","call","the","old","one","then","do","the","replacing","operation","of","substituting",",","for","each","(","name",",","self.replace_method",")","pair",",","the","named","method","with","the","returned","value","from","self.replace_method","."]
code: def __set_name__(self, owner, name):
      """
      Add the (name,self.replace_method) pair to the list named by replace_list_name in `owner`, creating the list and
      replacing the constructor of `owner` if necessary. The replaced constructor will call the old one then do the
      replacing operation of substituting, for each (name,self.replace_method) pair, the named method with the returned
      value from self.replace_method.
      """
      entry = (name, owner, self.replace_method)
  
      if not hasattr(owner, self.replace_list_name):
          oldinit = owner.__init__
  
          # replace the constructor with a new one which calls the old then replaces methods
          @wraps(oldinit)
          def newinit(_self, *args, **kwargs):
              oldinit(_self, *args, **kwargs)
  
              # replace each listed method of this newly constructed object
              for m, owner, replacer in getattr(
                  _self, self.replace_list_name
              ):
                  if isinstance(_self, owner):
                      meth = getattr(_self, m)
                      newmeth = replacer(meth)
                      setattr(_self, m, newmeth)
  
          owner.__init__ = newinit
          setattr(owner, self.replace_list_name, [entry])
      else:
          namelist = getattr(owner, self.replace_list_name)
  
          if not any(nl[0] == name for nl in namelist):
              namelist.append(entry)
  
      setattr(owner, name, self.meth)
  
file_path: MONAI/monai/utils/decorators.py
imports: from __future__ import annotations
  from functools import wraps
  from typing import Callable, Generator
label_desc: Use image node_id 3 for calling the MethodReplacer obj's underlying member method code with example usage: obj.__set_name__(owner, name) without return types