
from importlib.util import module_from_spec, spec_from_file_location


def import_file(name, file):
    """
    Import `file` as a module with _name_.

    Raises an ImportError if it could not be imported.
    """
    spec = spec_from_file_location(name, file)

    if not spec:
        raise ImportError("Could not import: '{}'".format(file))

    module = module_from_spec(spec)
    spec.loader.exec_module(module)
    return module


from sys import version_info


def import_file(name, file):
    """
    Import `file` as a module with _name_.

    Raises an ImportError if it could not be imported.
    """
    if version_info > (3, 5):
        from importlib.util import module_from_spec, spec_from_file_location

        spec = spec_from_file_location(name, file)

        if not spec:
            raise ImportError("Could not import: '{}'".format(file))

        module = module_from_spec(spec)
        spec.loader.exec_module(module)
        return module

    else:
        raise ImportError("Dymport: unsupported Python version, could not "
                          "import '{}'".format(file))

Add check for supported Python versions
Add check for supported Python versions

Not all Python versions are supported by this package, because the import
mechanism changes in the different Python versions.
If an unsupported Python version is used, an ImportError is raised.

  
- from importlib.util import module_from_spec, spec_from_file_location
+ from sys import version_info
  
  
  def import_file(name, file):
      """
      Import `file` as a module with _name_.
  
      Raises an ImportError if it could not be imported.
      """
-     spec = spec_from_file_location(name, file)
+     if version_info > (3, 5):
+         from importlib.util import module_from_spec, spec_from_file_location
  
+         spec = spec_from_file_location(name, file)
-     if not spec:
-         raise ImportError("Could not import: '{}'".format(file))
  
+         if not spec:
+             raise ImportError("Could not import: '{}'".format(file))
-     module = module_from_spec(spec)
-     spec.loader.exec_module(module)
-     return module
  
+         module = module_from_spec(spec)
+         spec.loader.exec_module(module)
+         return module
+ 
+     else:
+         raise ImportError("Dymport: unsupported Python version, could not "
+                           "import '{}'".format(file))
+ 
Add check for supported Python versions
## Code Before:

from importlib.util import module_from_spec, spec_from_file_location


def import_file(name, file):
    """
    Import `file` as a module with _name_.

    Raises an ImportError if it could not be imported.
    """
    spec = spec_from_file_location(name, file)

    if not spec:
        raise ImportError("Could not import: '{}'".format(file))

    module = module_from_spec(spec)
    spec.loader.exec_module(module)
    return module

## Instruction:
Add check for supported Python versions
## Code After:

from sys import version_info


def import_file(name, file):
    """
    Import `file` as a module with _name_.

    Raises an ImportError if it could not be imported.
    """
    if version_info > (3, 5):
        from importlib.util import module_from_spec, spec_from_file_location

        spec = spec_from_file_location(name, file)

        if not spec:
            raise ImportError("Could not import: '{}'".format(file))

        module = module_from_spec(spec)
        spec.loader.exec_module(module)
        return module

    else:
        raise ImportError("Dymport: unsupported Python version, could not "
                          "import '{}'".format(file))
