code: def get_parent(globals, level):
      """
      parent, name = get_parent(globals, level)
  
      Return the package that an import is being performed in.  If globals comes
      from the module foo.bar.bat (not itself a package), this returns the
      sys.modules entry for foo.bar.  If globals is from a package's __init__.py,
      the package's entry in sys.modules is returned.
  
      If globals doesn't come from a package or a module in a package, or a
      corresponding entry is not found in sys.modules, None is returned.
      """
      orig_level = level
  
      if not level or not isinstance(globals, dict):
          return None, ""
  
      pkgname = globals.get("__package__", None)
  
      if pkgname is not None:
          # __package__ is set, so use it
          if not hasattr(pkgname, "rindex"):
              raise ValueError("__package__ set to non-string")
          if len(pkgname) == 0:
              if level > 0:
                  raise ValueError(
                      "Attempted relative import in non-package"
                  )
              return None, ""
          name = pkgname
      else:
          # __package__ not set, so figure it out and set it
          if "__name__" not in globals:
              return None, ""
          modname = globals["__name__"]
  
          if "__path__" in globals:
              # __path__ is set, so modname is already the package name
              globals["__package__"] = name = modname
          else:
              # Normal module, so work out the package name if any
              lastdot = modname.rfind(".")
              if lastdot < 0 < level:
                  raise ValueError(
                      "Attempted relative import in non-package"
                  )
              if lastdot < 0:
                  globals["__package__"] = None
                  return None, ""
              globals["__package__"] = name = modname[:lastdot]
  
      dot = len(name)
      for x in range(level, 1, -1):
          try:
              dot = name.rindex(".", 0, dot)
          except ValueError as e:
              raise ValueError(
                  "attempted relative import beyond top-level "
                  "package"
              ) from e
      name = name[:dot]
  
      try:
          parent = sys.modules[name]
      except BaseException as e:
          if orig_level < 1:
              warn(
                  "Parent module '%.200s' not found while handling absolute "
                  "import" % name
              )
              parent = None
          else:
              raise SystemError(
                  "Parent module '%.200s' not loaded, cannot "
                  "perform relative import" % name
              ) from e
  
      # We expect, but can't guarantee, if parent != None, that:
      # - parent.__name__ == name
      # - parent.__dict__ is globals
      # If this is violated...  Who cares?
      return parent, name
  
file_path: catboost/contrib/python/ipython/py3/IPython/lib/deepreload.py
imports: import builtins
  from contextlib import contextmanager
  import importlib
  import sys
  from types import ModuleType
  from warnings import warn
  import types
label_desc: Use image node_id 2 for calling a global function with example usage: get_parent(globals, level) and returns: parent,  name, None,  str, None,  str, None,  str, None,  str