code: def nearest_base(cls, bases):
      '''Returns the closest ancestor to cls in bases.
      '''
      if cls in bases:
          return cls
  
      dists = {base: index(mro(cls), base) for base in bases}
      dists2 = {dist: base for base, dist in dists.items() if dist is not None}
      if not dists2:
          return None
      return dists2[min(dists2)f nearest_base(cls, bases):
      '''Returns the closest ancestor to cls in bases.
      '''
      if cls in bases:
          return cls
  
      dists = {base: index(mro(cls), base) for base in bases}
      dists2 = {dist: base for base, dist in dists.items() if dist is not None}
      if not dists2:
          return None
      return dists2[min(dists2)]
docs: Returns the closest ancestor to cls in bases.