code: def check_namespace(tree, stubtree, path, ignore=0):
      ret = 0
      count = 0
      tree_items = set(
          i.name
          for i in tree.body
          if hasattr(i, "name")
          and (not i.name.startswith("_") or i.name.endswith("__"))
      )
      stubtree_items = set(
          i.name
          for i in stubtree.body
          if hasattr(i, "name")
          and (not i.name.startswith("_") or i.name.endswith("__"))
      )
  
      for item in tree.body:
          if isinstance(item, ast.Assign):
              tree_items |= set(
                  i.id
                  for i in item.targets
                  if hasattr(i, "id")
                  and (not i.id.startswith("_") or i.id.endswith("__"))
              )
              for target in item.targets:
                  if isinstance(target, ast.Tuple):
                      tree_items |= set(i.id for i in target.elts)
          elif isinstance(item, ast.AnnAssign):
              tree_items |= {item.target.id}
      for item in stubtree.body:
          if isinstance(item, ast.Assign):
              stubtree_items |= set(
                  i.id
                  for i in item.targets
                  if hasattr(i, "id")
                  and (not i.id.startswith("_") or i.id.endswith("__"))
              )
              for target in item.targets:
                  if isinstance(target, ast.Tuple):
                      stubtree_items |= set(i.id for i in target.elts)
          elif isinstance(item, ast.AnnAssign):
              stubtree_items |= {item.target.id}
  
      try:
          all_ = ast.literal_eval(
              ast.unparse(get_subtree(tree, "__all__").value)
          )
      except ValueError:
          all_ = []
  
      if all_:
          missing = (tree_items - stubtree_items) & set(all_)
      else:
          missing = tree_items - stubtree_items
  
      deprecated = set()
      for item_name in missing:
          item = get_subtree(tree, item_name)
          if hasattr(item, "decorator_list"):
              if "deprecated" in [
                  i.func.attr
                  for i in item.decorator_list
                  if hasattr(i, "func") and hasattr(i.func, "attr")
              ]:
                  deprecated |= {item_name}
  
      if missing - deprecated and ~ignore & MISSING_STUB:
          print(f"{path}: {missing - deprecated} missing from stubs")
          ret |= MISSING_STUB
          count += 1
  
      non_class_or_func = set()
      for item_name in stubtree_items - tree_items:
          try:
              get_subtree(tree, item_name)
          except ValueError:
              pass
          else:
              non_class_or_func |= {item_name}
  
      missing_implementation = (
          stubtree_items - tree_items - non_class_or_func
      )
      if missing_implementation and ~ignore & MISSING_IMPL:
          print(
              f"{path}: {missing_implementation} in stubs and not source"
          )
          ret |= MISSING_IMPL
          count += 1
  
      for item_name in tree_items & stubtree_items:
          item = get_subtree(tree, item_name)
          stubitem = get_subtree(stubtree, item_name)
          if isinstance(item, ast.FunctionDef) and isinstance(
              stubitem, ast.FunctionDef
          ):
              err, c = check_function(
                  item, stubitem, f"{path}::{item_name}", ignore
              )
              ret |= err
              count += c
          if isinstance(item, ast.ClassDef):
              # Ignore set differences for classes... while it would be nice to have
              # inheritance and attributes set in init/methods make both presence and
              # absence of nodes spurious
              err, c = check_namespace(
                  item,
                  stubitem,
                  f"{path}::{item_name}",
                  ignore | MISSING_STUB | MISSING_IMPL,
              )
              ret |= err
              count += c
  
      return ret, count
  
imports: import ast
  import pathlib
  import sys
label_desc: Use image node_id 2 for calling a global function with example usage: check_namespace(tree, stubtree, path, ignore) and returns: ret,  count