code: def _walk(recursion):
      
      try:
          from scandir import walk as walk_function
      except ImportError:
          from os import walk as walk_function
  
      if recursion:
          walk = partial(walk_function)
      else:
          def walk(path):  # pylint: disable=C0111
              try:
                  yield next(walk_function(path))
              except NameError:
                  yield walk_function(path)
      return walk
docs: Returns a recursive or non-recursive directory walker