class_docstr: A dict subclass with attribute style access.
  
  This dict subclass has a a few extra features:
  
  * Attribute style access.
  * Protection of class members (like keys, items) when using attribute
    style access.
  * The ability to restrict assignment to only existing keys.
  * Intelligent merging.
  * Overloaded operators.
class_docstr_tok: ["A","dict","subclass","with","attribute","style","access",".","This","dict","subclass","has","a","a","few","extra","features",":","*","Attribute","style","access",".","*","Protection","of","class","members","(","like","keys",",","items",")","when","using","attribute","style","access",".","*","The","ability","to","restrict","assignment","to","only","existing","keys",".","*","Intelligent","merging",".","*","Overloaded","operators","."]
docstr: Set an attr with protection of class members.
  
  This calls :meth:`self.__setitem__` but convert :exc:`KeyError` to
  :exc:`AttributeError`.
  
  Examples
  --------
  
  >>> s = Struct()
  >>> s.a = 10
  >>> s.a
  10
  >>> try:
  ...     s.get = 10
  ... except AttributeError:
  ...     print("you can't set a class member")
  ...
  you can't set a class member
docstr_tok: ["Set","an","attr","with","protection","of","class","members",".","This","calls",":","meth",":","`","self.__setitem__","`","but","convert",":","exc",":","`","KeyError","`","to",":","exc",":","`","AttributeError","`",".","Examples","--","--","--","--",">",">",">","s","=","Struct","(",")",">",">",">","s.a","=","10",">",">",">","s.a","10",">",">",">","try",":","...","s.get","=","10","...","except","AttributeError",":","...","print","(","``","you","ca","n't","set","a","class","member","''",")","...","you","ca","n't","set","a","class","member"]
code: def __setattr__(self, key, value):
      """Set an attr with protection of class members.
  
      This calls :meth:`self.__setitem__` but convert :exc:`KeyError` to
      :exc:`AttributeError`.
  
      Examples
      --------
  
      >>> s = Struct()
      >>> s.a = 10
      >>> s.a
      10
      >>> try:
      ...     s.get = 10
      ... except AttributeError:
      ...     print("you can't set a class member")
      ...
      you can't set a class member
      """
      # If key is an str it might be a class member or instance var
      if isinstance(key, str):
          # I can't simply call hasattr here because it calls getattr, which
          # calls self.__getattr__, which returns True for keys in
          # self._data.  But I only want keys in the class and in
          # self.__dict__
          if key in self.__dict__ or hasattr(Struct, key):
              raise AttributeError(
                  "attr %s is a protected member of class Struct." % key
              )
      try:
          self.__setitem__(key, value)
      except KeyError as e:
          raise AttributeError(e)
  
file_path: catboost/contrib/python/ipython/py2/IPython/utils/ipstruct.py
label_desc: Use image node_id 3 for calling the Struct obj's underlying member method code with example usage: obj.__setattr__(key, value) without return types