class_docstr: Configuration object
  
  Provides default values configurable at different levels. The configuration object can have
  global default values, which may be overridden by user with yaml configuration files,
  environment variables or by setting directly the values in the configuration object. In order,
  direct definition overrides, environment variables, which overrides yaml configuration, which
  overrides default values in configuration object definition.
  
  Examples
  --------
  >>> config = Configuration()
  >>> config.add_option('test', str, 'hello', 'TEST_ENV')
  >>> config.test
  'hello'
  >>> config.load_yaml('some_config.yaml')
  >>> config.test
  'in yaml!'
  >>> os.environ['TEST_ENV'] = 'there!'
  >>> config.test
  'there!'
  >>> config.test = 'here'
  >>> config.test
  'here'
class_docstr_tok: ["Configuration","object","Provides","default","values","configurable","at","different","levels",".","The","configuration","object","can","have","global","default","values",",","which","may","be","overridden","by","user","with","yaml","configuration","files",",","environment","variables","or","by","setting","directly","the","values","in","the","configuration","object",".","In","order",",","direct","definition","overrides",",","environment","variables",",","which","overrides","yaml","configuration",",","which","overrides","default","values","in","configuration","object","definition",".","Examples","--","--","--","--",">",">",">","config","=","Configuration","(",")",">",">",">","config.add_option","(","'test","'",",","str",",","'hello","'",",","'TEST_ENV","'",")",">",">",">","config.test","'hello'",">",">",">","config.load_yaml","(","'some_config.yaml","'",")",">",">",">","config.test","'in","yaml","!","'",">",">",">","os.environ","[","'TEST_ENV","'","]","=","'there","!","'",">",">",">","config.test","'there","!","'",">",">",">","config.test","=","'here'",">",">",">","config.test","'here","'"]
docstr: Validate the (key, value) option
  
  Raises
  ------
  TypeError
      - If the value is a Configuration object while the key is defined as a normal field
        (str, int, bool, etc). It cannot be overwritten by a subconfiguration.
      - If the type of `value` is not valid for `key`.
docstr_tok: ["Validate","the","(","key",",","value",")","option","Raises","--","--","--","TypeError","-","If","the","value","is","a","Configuration","object","while","the","key","is","defined","as","a","normal","field","(","str",",","int",",","bool",",","etc",")",".","It","can","not","be","overwritten","by","a","subconfiguration",".","-","If","the","type","of","`","value","`","is","not","valid","for","`","key","`","."]
code: def _validate(self, key, value):
      """Validate the (key, value) option
  
      Raises
      ------
      TypeError
          - If the value is a Configuration object while the key is defined as a normal field
            (str, int, bool, etc). It cannot be overwritten by a subconfiguration.
          - If the type of `value` is not valid for `key`.
  
      """
      if isinstance(value, Configuration):
          raise TypeError(
              f"Cannot overwrite option {key} with a configuration"
          )
  
      try:
          self._config[key]["type"](value)
      except ValueError as e:
          message = (
              f"Option {key} of type {self._config[key]['type']} "
              f"cannot be set to {value} with type {type(value)}"
          )
          raise TypeError(message) from e
  
imports: import contextlib
  import logging
  import os
  import pprint
  import yaml
label_desc: Use image node_id 8 for calling the Configuration obj's underlying member method code with example usage: obj._validate(key, value) without return types