# Buggy code
def _iter_non_pyc_files(cls, directory):
    # type: (str) -> Iterator[str]
    normpath = os.path.realpath(os.path.normpath(directory))
    for root, dirs, files in os.walk(normpath):
        dirs[:] = [d for d in dirs if d != "__pycache__"]
        for f in files:
            # For Python 2.7, `.pyc` files are compiled as siblings to `.py` files (there is no
            # __pycache__ dir. We rely on the fact that the temporary files created by CPython
            # have object id (integer) suffixes to avoid picking up either finished `.pyc` files
            # or files where Python bytecode compilation is in-flight; i.e.:
            # `.pyc.0123456789`-style files.
            if not re.search(r"\.pyc(?:\.[0-9]+)?$", f):
                yield os.path.relpath(os.path.join(root, f), normpath)


# Traceback (FileNotFoundError)
Engine traceback:
in select
in pants.core.goals.typecheck.typecheck
in pants.backend.python.typecheck.mypy.rules.mypy_typecheck
in pants.backend.python.typecheck.mypy.rules.mypy_typecheck_partition
in pants.backend.python.util_rules.pex.create_pex
in pants.backend.python.util_rules.pex.find_interpreter (CPython<3.9,<4,>=3.7,>=3.8)
in pants.engine.process.fallible_to_exec_result_or_raise
Traceback (most recent call last):
File "/home/toolchain/.*****/pants/setup/bootstrap-Linux-x86_64/2.1.0.dev0_py38/lib/python3.8/site-packages/pants/engine/process.py", line 241, in fallible_to_exec_result_or_raise
raise ProcessExecutionFailure(
pants.engine.process.ProcessExecutionFailure: Process 'Find interpreter for constraints: CPython<3.9,<4,>=3.7,>=3.8' failed with exit code 1.
stdout:

stderr:
Traceback (most recent call last):
File "/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.bootstrap/pex/pex.py", line 443, in execute
exit_code = self._wrap_coverage(self._wrap_profiling, self._execute)
File "/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.bootstrap/pex/pex.py", line 375, in _wrap_coverage
return runner(*args)
File "/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.bootstrap/pex/pex.py", line 406, in _wrap_profiling
return runner(*args)
File "/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.bootstrap/pex/pex.py", line 494, in _execute
return self.execute_entry(self._pex_info.entry_point)
File "/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.bootstrap/pex/pex.py", line 596, in execute_entry
return runner(entry_point)
File "/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.bootstrap/pex/pex.py", line 612, in execute_pkg_resources
return runner()
File "/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.deps/pex-2.1.20-py2.py3-none-any.whl/pex/bin/pex.py", line 994, in main
pex_builder.freeze(bytecode_compile=options.compile)
File "/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.deps/pex-2.1.20-py2.py3-none-any.whl/pex/pex_builder.py", line 505, in freeze
self._prepare_bootstrap()
File "/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.deps/pex-2.1.20-py2.py3-none-any.whl/pex/pex_builder.py", line 463, in _prepare_bootstrap
vendor.vendor_runtime(
File "/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.deps/pex-2.1.20-py2.py3-none-any.whl/pex/vendor/__init__.py", line 166, in vendor_runtime
chroot.copy(src, dest, label)
File "/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.deps/pex-2.1.20-py2.py3-none-any.whl/pex/common.py", line 512, in copy
shutil.copy(src, os.path.join(self.chroot, dst))
File "/usr/local/lib/python3.8/shutil.py", line 415, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/local/lib/python3.8/shutil.py", line 261, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: '/home/toolchain/.*****/pants/named_*****s/pex_root/unzipped_pexes/d7ed954089c1232b9c1a001845a5a384366d3669/.deps/pex-2.1.20-py2.py3-none-any.whl/pex/vendor/_vendored/setuptools/pkg_resources/_vendor/__py*****__/pyparsing.cpython-37.pyc.140210639452464'

# Fixed code
def _iter_non_pyc_files(cls, directory):
    # type: (str) -> Iterator[str]
    normpath = os.path.realpath(os.path.normpath(directory))
    for root, dirs, files in os.walk(normpath):
        dirs[:] = list(filter_pyc_dirs(dirs))
        for f in filter_pyc_files(files):
            yield os.path.relpath(os.path.join(root, f), normpath)