prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  LuigiConfigParser::add_config_path() raises if instance() hasn't been accessed
  To add a path to the list of config paths, one currently has to do:
  
  ``` python
  LuigiConfigParser.instance()  # remove this and get an exception
  LuigiConfigParser.add_config_path(my_path)
  ```
  
  because `add_config_path` tries to reload `cls._instance` which is initialized with `None`. Wouldn't it be cleaner to do a check there and only reload a non-null instance?
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `luigi/configuration.py`
  Content:
  ```
  1 
  2 import os
  3 import logging
  4 from ConfigParser import ConfigParser, NoOptionError, NoSectionError
  5 
  6 
  7 class LuigiConfigParser(ConfigParser):
  8     NO_DEFAULT = object()
  9     _instance = None
  10     _config_paths = ['/etc/luigi/client.cfg', 'client.cfg']
  11     if 'LUIGI_CONFIG_PATH' in os.environ:
  12         _config_paths.append(os.environ['LUIGI_CONFIG_PATH'])
  13 
  14     @classmethod
  15     def add_config_path(cls, path):
  16         cls._config_paths.append(path)
  17         cls._instance.reload()
  18 
  19     @classmethod
  20     def instance(cls, *args, **kwargs):
  21         """ Singleton getter """
  22         if cls._instance is None:
  23             cls._instance = cls(*args, **kwargs)
  24             loaded = cls._instance.reload()
  25             logging.getLogger('luigi-interface').info('Loaded %r', loaded)
  26 
  27         return cls._instance
  28 
  29     def reload(self):
  30         return self._instance.read(self._config_paths)
  31 
  32     def _get_with_default(self, method, section, option, default, expected_type=None):
  33         """ Gets the value of the section/option using method. Returns default if value
  34         is not found. Raises an exception if the default value is not None and doesn't match
  35         the expected_type.
  36         """
  37         try:
  38             return method(self, section, option)
  39         except (NoOptionError, NoSectionError):
  40             if default is LuigiConfigParser.NO_DEFAULT:
  41                 raise
  42             if expected_type is not None and default is not None and \
  43                not isinstance(default, expected_type):
  44                 raise
  45             return default
  46 
  47     def get(self, section, option, default=NO_DEFAULT):
  48         return self._get_with_default(ConfigParser.get, section, option, default)
  49 
  50     def getboolean(self, section, option, default=NO_DEFAULT):
  51         return self._get_with_default(ConfigParser.getboolean, section, option, default, bool)
  52 
  53     def getint(self, section, option, default=NO_DEFAULT):
  54         return self._get_with_default(ConfigParser.getint, section, option, default, int)
  55 
  56     def getfloat(self, section, option, default=NO_DEFAULT):
  57         return self._get_with_default(ConfigParser.getfloat, section, option, default, float)
  58 
  59     def set(self, section, option, value):
  60         if not ConfigParser.has_section(self, section):
  61             ConfigParser.add_section(self, section)
  62 
  63         return ConfigParser.set(self, section, option, value)
  64 
  65 def get_config():
  66     """ Convenience method (for backwards compatibility) for accessing config singleton """
  67     return LuigiConfigParser.instance()
  68
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/luigi/configuration.py b/luigi/configuration.py
  --- a/luigi/configuration.py
  +++ b/luigi/configuration.py
  @@ -14,7 +14,7 @@
       @classmethod
       def add_config_path(cls, path):
           cls._config_paths.append(path)
  -        cls._instance.reload()
  +        cls.reload()
   
       @classmethod
       def instance(cls, *args, **kwargs):
  @@ -26,8 +26,9 @@
   
           return cls._instance
   
  -    def reload(self):
  -        return self._instance.read(self._config_paths)
  +    @classmethod
  +    def reload(cls):
  +        return cls.instance().read(cls._config_paths)
   
       def _get_with_default(self, method, section, option, default, expected_type=None):
           """ Gets the value of the section/option using method. Returns default if value
  
verification_info: {"golden_diff": "diff --git a/luigi/configuration.py b/luigi/configuration.py\n--- a/luigi/configuration.py\n+++ b/luigi/configuration.py\n@@ -14,7 +14,7 @@\n     @classmethod\n     def add_config_path(cls, path):\n         cls._config_paths.append(path)\n-        cls._instance.reload()\n+        cls.reload()\n \n     @classmethod\n     def instance(cls, *args, **kwargs):\n@@ -26,8 +26,9 @@\n \n         return cls._instance\n \n-    def reload(self):\n-        return self._instance.read(self._config_paths)\n+    @classmethod\n+    def reload(cls):\n+        return cls.instance().read(cls._config_paths)\n \n     def _get_with_default(self, method, section, option, default, expected_type=None):\n         \"\"\" Gets the value of the section/option using method. Returns default if value\n", "issue": "LuigiConfigParser::add_config_path() raises if instance() hasn't been accessed\nTo add a path to the list of config paths, one currently has to do:\n\n``` python\nLuigiConfigParser.instance()  # remove this and get an exception\nLuigiConfigParser.add_config_path(my_path)\n```\n\nbecause `add_config_path` tries to reload `cls._instance` which is initialized with `None`. Wouldn't it be cleaner to do a check there and only reload a non-null instance?\n\n", "before_files": [{"content": "\nimport os\nimport logging\nfrom ConfigParser import ConfigParser, NoOptionError, NoSectionError\n\n\nclass LuigiConfigParser(ConfigParser):\n    NO_DEFAULT = object()\n    _instance = None\n    _config_paths = ['/etc/luigi/client.cfg', 'client.cfg']\n    if 'LUIGI_CONFIG_PATH' in os.environ:\n        _config_paths.append(os.environ['LUIGI_CONFIG_PATH'])\n\n    @classmethod\n    def add_config_path(cls, path):\n        cls._config_paths.append(path)\n        cls._instance.reload()\n\n    @classmethod\n    def instance(cls, *args, **kwargs):\n        \"\"\" Singleton getter \"\"\"\n        if cls._instance is None:\n            cls._instance = cls(*args, **kwargs)\n            loaded = cls._instance.reload()\n            logging.getLogger('luigi-interface').info('Loaded %r', loaded)\n\n        return cls._instance\n\n    def reload(self):\n        return self._instance.read(self._config_paths)\n\n    def _get_with_default(self, method, section, option, default, expected_type=None):\n        \"\"\" Gets the value of the section/option using method. Returns default if value\n        is not found. Raises an exception if the default value is not None and doesn't match\n        the expected_type.\n        \"\"\"\n        try:\n            return method(self, section, option)\n        except (NoOptionError, NoSectionError):\n            if default is LuigiConfigParser.NO_DEFAULT:\n                raise\n            if expected_type is not None and default is not None and \\\n               not isinstance(default, expected_type):\n                raise\n            return default\n\n    def get(self, section, option, default=NO_DEFAULT):\n        return self._get_with_default(ConfigParser.get, section, option, default)\n\n    def getboolean(self, section, option, default=NO_DEFAULT):\n        return self._get_with_default(ConfigParser.getboolean, section, option, default, bool)\n\n    def getint(self, section, option, default=NO_DEFAULT):\n        return self._get_with_default(ConfigParser.getint, section, option, default, int)\n\n    def getfloat(self, section, option, default=NO_DEFAULT):\n        return self._get_with_default(ConfigParser.getfloat, section, option, default, float)\n\n    def set(self, section, option, value):\n        if not ConfigParser.has_section(self, section):\n            ConfigParser.add_section(self, section)\n\n        return ConfigParser.set(self, section, option, value)\n\ndef get_config():\n    \"\"\" Convenience method (for backwards compatibility) for accessing config singleton \"\"\"\n    return LuigiConfigParser.instance()\n", "path": "luigi/configuration.py"}], "after_files": [{"content": "\nimport os\nimport logging\nfrom ConfigParser import ConfigParser, NoOptionError, NoSectionError\n\n\nclass LuigiConfigParser(ConfigParser):\n    NO_DEFAULT = object()\n    _instance = None\n    _config_paths = ['/etc/luigi/client.cfg', 'client.cfg']\n    if 'LUIGI_CONFIG_PATH' in os.environ:\n        _config_paths.append(os.environ['LUIGI_CONFIG_PATH'])\n\n    @classmethod\n    def add_config_path(cls, path):\n        cls._config_paths.append(path)\n        cls.reload()\n\n    @classmethod\n    def instance(cls, *args, **kwargs):\n        \"\"\" Singleton getter \"\"\"\n        if cls._instance is None:\n            cls._instance = cls(*args, **kwargs)\n            loaded = cls._instance.reload()\n            logging.getLogger('luigi-interface').info('Loaded %r', loaded)\n\n        return cls._instance\n\n    @classmethod\n    def reload(cls):\n        return cls.instance().read(cls._config_paths)\n\n    def _get_with_default(self, method, section, option, default, expected_type=None):\n        \"\"\" Gets the value of the section/option using method. Returns default if value\n        is not found. Raises an exception if the default value is not None and doesn't match\n        the expected_type.\n        \"\"\"\n        try:\n            return method(self, section, option)\n        except (NoOptionError, NoSectionError):\n            if default is LuigiConfigParser.NO_DEFAULT:\n                raise\n            if expected_type is not None and default is not None and \\\n               not isinstance(default, expected_type):\n                raise\n            return default\n\n    def get(self, section, option, default=NO_DEFAULT):\n        return self._get_with_default(ConfigParser.get, section, option, default)\n\n    def getboolean(self, section, option, default=NO_DEFAULT):\n        return self._get_with_default(ConfigParser.getboolean, section, option, default, bool)\n\n    def getint(self, section, option, default=NO_DEFAULT):\n        return self._get_with_default(ConfigParser.getint, section, option, default, int)\n\n    def getfloat(self, section, option, default=NO_DEFAULT):\n        return self._get_with_default(ConfigParser.getfloat, section, option, default, float)\n\n    def set(self, section, option, value):\n        if not ConfigParser.has_section(self, section):\n            ConfigParser.add_section(self, section)\n\n        return ConfigParser.set(self, section, option, value)\n\ndef get_config():\n    \"\"\" Convenience method (for backwards compatibility) for accessing config singleton \"\"\"\n    return LuigiConfigParser.instance()\n", "path": "luigi/configuration.py"}]}