import os
import importlib
from functools import wraps
from . import cython
try:
    from . import numba
except ModuleNotFoundError:
    numba = None

def optimizer(func):
    """Decorator used to wrap calls to optimized versions of functions."""
    from shenfun.config import config
    mod = config['optimization']['mode']
    verbose = config['optimization']['verbose']
    if mod.lower() not in ('cython', 'numba'):
        # Use python function
        if verbose:
            print(func.__name__ + ' not optimized')
        return func
    mod = importlib.import_module('shenfun.optimization.'+mod.lower())
    fun = getattr(mod, func.__name__, func)
    if verbose:
        if fun is func:
            print(fun.__name__ + ' not optimized')

    @wraps(func)
    def wrapped_function(*args, **kwargs):
        u0 = fun(*args, **kwargs)
        return u0

    return wrapped_function

import os
import importlib
from functools import wraps
from . import cython
try:
    from . import numba
except ModuleNotFoundError:
    numba = None

def optimizer(func):
    """Decorator used to wrap calls to optimized versions of functions."""
    from shenfun.config import config
    mod = 'cython'
    verbose = False
    try:
        mod = config['optimization']['mode']
        verbose = config['optimization']['verbose']
    except KeyError:
        pass

    if mod.lower() not in ('cython', 'numba'):
        # Use python function
        if verbose:
            print(func.__name__ + ' not optimized')
        return func
    mod = importlib.import_module('shenfun.optimization.'+mod.lower())
    fun = getattr(mod, func.__name__, func)
    if verbose:
        if fun is func:
            print(fun.__name__ + ' not optimized')

    @wraps(func)
    def wrapped_function(*args, **kwargs):
        u0 = fun(*args, **kwargs)
        return u0

    return wrapped_function

Use try clause for config in optimizer
Use try clause for config in optimizer

  import os
  import importlib
  from functools import wraps
  from . import cython
  try:
      from . import numba
  except ModuleNotFoundError:
      numba = None
  
  def optimizer(func):
      """Decorator used to wrap calls to optimized versions of functions."""
      from shenfun.config import config
+     mod = 'cython'
+     verbose = False
+     try:
-     mod = config['optimization']['mode']
+         mod = config['optimization']['mode']
-     verbose = config['optimization']['verbose']
+         verbose = config['optimization']['verbose']
+     except KeyError:
+         pass
+ 
      if mod.lower() not in ('cython', 'numba'):
          # Use python function
          if verbose:
              print(func.__name__ + ' not optimized')
          return func
      mod = importlib.import_module('shenfun.optimization.'+mod.lower())
      fun = getattr(mod, func.__name__, func)
      if verbose:
          if fun is func:
              print(fun.__name__ + ' not optimized')
  
      @wraps(func)
      def wrapped_function(*args, **kwargs):
          u0 = fun(*args, **kwargs)
          return u0
  
      return wrapped_function
  
Use try clause for config in optimizer
## Code Before:
import os
import importlib
from functools import wraps
from . import cython
try:
    from . import numba
except ModuleNotFoundError:
    numba = None

def optimizer(func):
    """Decorator used to wrap calls to optimized versions of functions."""
    from shenfun.config import config
    mod = config['optimization']['mode']
    verbose = config['optimization']['verbose']
    if mod.lower() not in ('cython', 'numba'):
        # Use python function
        if verbose:
            print(func.__name__ + ' not optimized')
        return func
    mod = importlib.import_module('shenfun.optimization.'+mod.lower())
    fun = getattr(mod, func.__name__, func)
    if verbose:
        if fun is func:
            print(fun.__name__ + ' not optimized')

    @wraps(func)
    def wrapped_function(*args, **kwargs):
        u0 = fun(*args, **kwargs)
        return u0

    return wrapped_function

## Instruction:
Use try clause for config in optimizer
## Code After:
import os
import importlib
from functools import wraps
from . import cython
try:
    from . import numba
except ModuleNotFoundError:
    numba = None

def optimizer(func):
    """Decorator used to wrap calls to optimized versions of functions."""
    from shenfun.config import config
    mod = 'cython'
    verbose = False
    try:
        mod = config['optimization']['mode']
        verbose = config['optimization']['verbose']
    except KeyError:
        pass

    if mod.lower() not in ('cython', 'numba'):
        # Use python function
        if verbose:
            print(func.__name__ + ' not optimized')
        return func
    mod = importlib.import_module('shenfun.optimization.'+mod.lower())
    fun = getattr(mod, func.__name__, func)
    if verbose:
        if fun is func:
            print(fun.__name__ + ' not optimized')

    @wraps(func)
    def wrapped_function(*args, **kwargs):
        u0 = fun(*args, **kwargs)
        return u0

    return wrapped_function
