# Buggy code
def _build(
    sources: List[BuildSource],
    options: Options,
    alt_lib_path: Optional[str],
    bin_dir: Optional[str],
    flush_errors: Callable[[List[str], bool], None],
    fscache: Optional[FileSystemCache],
) -> BuildResult:
    # This seems the most reasonable place to tune garbage collection.
    gc.set_threshold(50000)

    data_dir = default_data_dir(bin_dir)
    fscache = fscache or FileSystemCache()

    search_paths = compute_search_paths(
        sources, options, data_dir, fscache, alt_lib_path
    )

    reports = Reports(data_dir, options.report_dirs)
    source_set = BuildSourceSet(sources)
    errors = Errors(options.show_error_context, options.show_column_numbers)
    plugin = load_plugins(options, errors)

    # Construct a build manager object to hold state during the build.
    #
    # Ignore current directory prefix in error messages.
    manager = BuildManager(
        data_dir,
        search_paths,
        ignore_prefix=os.getcwd(),
        source_set=source_set,
        reports=reports,
        options=options,
        version_id=__version__,
        plugin=plugin,
        errors=errors,
        flush_errors=flush_errors,
        fscache=fscache,
    )

    reset_global_state()
    try:
        graph = dispatch(sources, manager)
        if not options.fine_grained_incremental:
            TypeState.reset_all_subtype_caches()
        return BuildResult(manager, graph)
    finally:
        manager.log(
            "Build finished in %.3f seconds with %d modules, and %d errors"
            % (
                time.time() - manager.start_time,
                len(manager.modules),
                manager.errors.num_messages(),
            )
        )
        # Finish the HTML or XML reports even if CompileError was raised.
        reports.finish()


# Traceback (AssertionError)
./contrib/sacrebleu/sacrebleu.py: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.610
Traceback (most recent call last):
File "/usr/local/bin/mypy", line 11, in <module>
sys.exit(console_entry())
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry
main(None)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/main.py", line 91, in main
res = type_check_only(sources, bin_dir, options, flush_errors, fscache)  # noqa
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/main.py", line 148, in type_check_only
fscache=fscache)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 185, in build
flush_errors, fscache)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 285, in _build
graph = dispatch(sources, manager)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 2398, in dispatch
process_graph(graph, manager)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 2691, in process_graph
process_stale_scc(graph, scc, manager)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 2801, in process_stale_scc
graph[id].semantic_analysis()
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 2009, in semantic_analysis
self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 1818, in wrap_context
yield
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 2009, in semantic_analysis
self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/semanal.py", line 291, in visit_file
v.type = self.anal_type(v.type)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/semanal.py", line 1578, in anal_type
typ = t.accept(a)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/types.py", line 203, in accept
return visitor.visit_unbound_type(self)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/typeanal.py", line 178, in visit_unbound_type
typ = self.visit_unbound_type_nonoptional(t)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/typeanal.py", line 186, in visit_unbound_type_nonoptional
sym = self.lookup(t.name, t, suppress_errors=self.third_pass)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/semanal.py", line 3058, in lookup_qualified
n = self.lookup(parts[0], ctx, suppress_errors=suppress_errors)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/semanal.py", line 3038, in lookup
self.name_not_defined(name, ctx)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/semanal.py", line 3246, in name_not_defined
self.fail(message, ctx)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/semanal.py", line 3281, in fail
self.errors.report(ctx.get_line(), ctx.get_column(), msg, blocker=blocker)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/errors.py", line 260, in report
target=self.current_target())
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/errors.py", line 208, in current_target
return self.scope.current_target()
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/scope.py", line 30, in current_target
assert self.module
AssertionError:
./contrib/sacrebleu/sacrebleu.py: : note: use --pdb to drop into pdb

# Fixed code
def _build(
    sources: List[BuildSource],
    options: Options,
    alt_lib_path: Optional[str],
    bin_dir: Optional[str],
    flush_errors: Callable[[List[str], bool], None],
    fscache: Optional[FileSystemCache],
) -> BuildResult:
    # This seems the most reasonable place to tune garbage collection.
    gc.set_threshold(50000)

    data_dir = default_data_dir()
    fscache = fscache or FileSystemCache()

    search_paths = compute_search_paths(
        sources, options, data_dir, fscache, alt_lib_path
    )

    reports = Reports(data_dir, options.report_dirs)
    source_set = BuildSourceSet(sources)
    errors = Errors(options.show_error_context, options.show_column_numbers)
    plugin = load_plugins(options, errors)

    # Construct a build manager object to hold state during the build.
    #
    # Ignore current directory prefix in error messages.
    manager = BuildManager(
        data_dir,
        search_paths,
        ignore_prefix=os.getcwd(),
        source_set=source_set,
        reports=reports,
        options=options,
        version_id=__version__,
        plugin=plugin,
        errors=errors,
        flush_errors=flush_errors,
        fscache=fscache,
    )

    reset_global_state()
    try:
        graph = dispatch(sources, manager)
        if not options.fine_grained_incremental:
            TypeState.reset_all_subtype_caches()
        return BuildResult(manager, graph)
    finally:
        manager.log(
            "Build finished in %.3f seconds with %d modules, and %d errors"
            % (
                time.time() - manager.start_time,
                len(manager.modules),
                manager.errors.num_messages(),
            )
        )
        # Finish the HTML or XML reports even if CompileError was raised.
        reports.finish()