import sys


def import_attribute(import_path, exception_handler=None):
    from django.utils.importlib import import_module
    module_name, object_name = import_path.rsplit('.', 1)
    try:
        module = import_module(module_name)
    except:  # pragma: no cover
        if callable(exception_handler):
            exctype, excvalue, tb = sys.exc_info()
            return exception_handler(import_path, exctype, excvalue, tb)
        else:
            raise
    try:
        return getattr(module, object_name)
    except:  # pragma: no cover
        if callable(exception_handler):
            exctype, excvalue, tb = sys.exc_info()
            return exception_handler(import_path, exctype, excvalue, tb)
        else:
            raise

import sys


def import_attribute(import_path, exception_handler=None):
    try:
        from importlib import import_module
    except ImportError:
        from django.utils.importlib import import_module
    module_name, object_name = import_path.rsplit('.', 1)
    try:
        module = import_module(module_name)
    except:  # pragma: no cover
        if callable(exception_handler):
            exctype, excvalue, tb = sys.exc_info()
            return exception_handler(import_path, exctype, excvalue, tb)
        else:
            raise
    try:
        return getattr(module, object_name)
    except:  # pragma: no cover
        if callable(exception_handler):
            exctype, excvalue, tb = sys.exc_info()
            return exception_handler(import_path, exctype, excvalue, tb)
        else:
            raise

Use import_module from standard library if exists
Use import_module from standard library if exists

Django 1.8+ drops `django.utils.importlib`. I imagine because that is because an older version of Python (either 2.5 and/or 2.6) is being dropped. I haven't checked older versions but `importlib` exists in Python 2.7.
  import sys
  
  
  def import_attribute(import_path, exception_handler=None):
+     try:
+         from importlib import import_module
+     except ImportError:
-     from django.utils.importlib import import_module
+         from django.utils.importlib import import_module
      module_name, object_name = import_path.rsplit('.', 1)
      try:
          module = import_module(module_name)
      except:  # pragma: no cover
          if callable(exception_handler):
              exctype, excvalue, tb = sys.exc_info()
              return exception_handler(import_path, exctype, excvalue, tb)
          else:
              raise
      try:
          return getattr(module, object_name)
      except:  # pragma: no cover
          if callable(exception_handler):
              exctype, excvalue, tb = sys.exc_info()
              return exception_handler(import_path, exctype, excvalue, tb)
          else:
              raise
  
Use import_module from standard library if exists
## Code Before:
import sys


def import_attribute(import_path, exception_handler=None):
    from django.utils.importlib import import_module
    module_name, object_name = import_path.rsplit('.', 1)
    try:
        module = import_module(module_name)
    except:  # pragma: no cover
        if callable(exception_handler):
            exctype, excvalue, tb = sys.exc_info()
            return exception_handler(import_path, exctype, excvalue, tb)
        else:
            raise
    try:
        return getattr(module, object_name)
    except:  # pragma: no cover
        if callable(exception_handler):
            exctype, excvalue, tb = sys.exc_info()
            return exception_handler(import_path, exctype, excvalue, tb)
        else:
            raise

## Instruction:
Use import_module from standard library if exists
## Code After:
import sys


def import_attribute(import_path, exception_handler=None):
    try:
        from importlib import import_module
    except ImportError:
        from django.utils.importlib import import_module
    module_name, object_name = import_path.rsplit('.', 1)
    try:
        module = import_module(module_name)
    except:  # pragma: no cover
        if callable(exception_handler):
            exctype, excvalue, tb = sys.exc_info()
            return exception_handler(import_path, exctype, excvalue, tb)
        else:
            raise
    try:
        return getattr(module, object_name)
    except:  # pragma: no cover
        if callable(exception_handler):
            exctype, excvalue, tb = sys.exc_info()
            return exception_handler(import_path, exctype, excvalue, tb)
        else:
            raise
