parameters: (name, path, target=None)
docstring: Find a module's spec.
docstring_summary: Find a module's spec.
docstring_tokens: Find a module s spec .
function: def _find_spec(name, path, target=None):
      """Find a module's spec."""
      meta_path = sys.meta_path
      if meta_path is None:
          # PyImport_Cleanup() is running or has been called.
          raise ImportError("sys.meta_path is None, Python is likely "
                            "shutting down")
  
      if not meta_path:
          _warnings.warn('sys.meta_path is empty', ImportWarning)
  
      # We check sys.modules here for the reload case.  While a passed-in
      # target will usually indicate a reload there is no guarantee, whereas
      # sys.modules provides one.
      is_reload = name in sys.modules
      for finder in meta_path:
          with _ImportLockContext():
              try:
                  find_spec = finder.find_spec
              except AttributeError:
                  spec = _find_spec_legacy(finder, name, path)
                  if spec is None:
                      continue
              else:
                  spec = find_spec(name, path, target)
          if spec is not None:
              # The parent import may have already imported this module.
              if not is_reload and name in sys.modules:
                  module = sys.modules[name]
                  try:
                      __spec__ = module.__spec__
                  except AttributeError:
                      # We use the found spec since that is the one that
                      # we would have used if the parent module hadn't
                      # beaten us to the punch.
                      return spec
                  else:
                      if __spec__ is None:
                          return spec
                      else:
                          return __spec__
              else:
                  return spec
      else:
          return None
function_tokens: def _find_spec ( name , path , target = None ) : meta_path = sys . meta_path if meta_path is None : # PyImport_Cleanup() is running or has been called. raise ImportError ( "sys.meta_path is None, Python is likely " "shutting down" ) if not meta_path : _warnings . warn ( 'sys.meta_path is empty' , ImportWarning ) # We check sys.modules here for the reload case.  While a passed-in # target will usually indicate a reload there is no guarantee, whereas # sys.modules provides one. is_reload = name in sys . modules for finder in meta_path : with _ImportLockContext ( ) : try : find_spec = finder . find_spec except AttributeError : spec = _find_spec_legacy ( finder , name , path ) if spec is None : continue else : spec = find_spec ( name , path , target ) if spec is not None : # The parent import may have already imported this module. if not is_reload and name in sys . modules : module = sys . modules [ name ] try : __spec__ = module . __spec__ except AttributeError : # We use the found spec since that is the one that # we would have used if the parent module hadn't # beaten us to the punch. return spec else : if __spec__ is None : return spec else : return __spec__ else : return spec else : return None