# Buggy code
def find_targets_recursive(
    manager: BuildManager,
    graph: Graph,
    triggers: Set[str],
    deps: Dict[str, Set[str]],
    up_to_date_modules: Set[str],
) -> Tuple[Dict[str, Set[DeferredNode]], Set[str], Set[TypeInfo]]:
    """Find names of all targets that need to reprocessed, given some triggers.

    Returns: A tuple containing a:
     * Dictionary from module id to a set of stale targets.
     * A set of module ids for unparsed modules with stale targets.
    """
    result = {}  # type: Dict[str, Set[DeferredNode]]
    worklist = triggers
    processed = set()  # type: Set[str]
    stale_protos = set()  # type: Set[TypeInfo]
    unloaded_files = set()  # type: Set[str]

    # Find AST nodes corresponding to each target.
    #
    # TODO: Don't rely on a set, since the items are in an unpredictable order.
    while worklist:
        processed |= worklist
        current = worklist
        worklist = set()
        for target in current:
            if target.startswith("<"):
                worklist |= deps.get(target, set()) - processed
            else:
                module_id = module_prefix(graph, target)
                if module_id is None:
                    # Deleted module.
                    continue
                if module_id in up_to_date_modules:
                    # Already processed.
                    continue
                if (
                    module_id not in manager.modules
                    or manager.modules[module_id].is_cache_skeleton
                ):
                    # We haven't actually parsed and checked the module, so we don't have
                    # access to the actual nodes.
                    # Add it to the queue of files that need to be processed fully.
                    unloaded_files.add(module_id)
                    continue

                if module_id not in result:
                    result[module_id] = set()
                manager.log_fine_grained("process: %s" % target)
                deferred, stale_proto = lookup_target(manager, target)
                if stale_proto:
                    stale_protos.add(stale_proto)
                result[module_id].update(deferred)

    return result, unloaded_files, stale_protos


# Traceback (AssertionError)
pymc3/model.py:672: error: Decorated property not supported
pymc3/variational/opvi.py:1556: error: Decorated property not supported
pymc3/variational/flows.py:193: error: Decorated property not supported
pymc3/__init__.py:25: error: Name 'utils' already defined (by an import)
pymc3/data.py:226: error: Need type annotation for 'RNG'
Traceback (most recent call last):
File "/Users/rpg/Library/Python/3.7/bin/mypy", line 11, in <module>
sys.exit(console_entry())
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/__main__.py", line 7, in console_entry
main(None)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/main.py", line 91, in main
res = type_check_only(sources, bin_dir, options, flush_errors, fscache)  # noqa
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/main.py", line 148, in type_check_only
fscache=fscache)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 177, in build
flush_errors, fscache)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 350, in _build
graph = dispatch(sources, manager)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2560, in dispatch
process_graph(graph, manager)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2853, in process_graph
process_stale_scc(graph, scc, manager)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2976, in process_stale_scc
graph[id].type_check_first_pass()
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/build.py", line 2151, in type_check_first_pass
self.type_checker().check_first_pass()
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 253, in check_first_pass
self.accept(d)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 352, in accept
stmt.accept(self)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/nodes.py", line 808, in accept
return visitor.visit_class_def(self)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1368, in visit_class_def
self.accept(defn.defs)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 352, in accept
stmt.accept(self)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/nodes.py", line 873, in accept
return visitor.visit_block(self)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1514, in visit_block
self.accept(s)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 352, in accept
stmt.accept(self)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/nodes.py", line 443, in accept
return visitor.visit_overloaded_func_def(self)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 385, in visit_overloaded_func_def
self._visit_overloaded_func_def(defn)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 409, in _visit_overloaded_func_def
self.check_method_override(defn)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1198, in check_method_override
self.check_method_or_accessor_override_for_base(defn, base)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1208, in check_method_or_accessor_override_for_base
self.check_method_override_for_base_with_name(defn, name, base)
File "/Users/rpg/Library/Python/3.7/lib/python/site-packages/mypy/checker.py", line 1252, in check_method_override_for_base_with_name
assert False, str(base_attr.node)
AssertionError: Var(sampler_vars)

# Fixed code
def find_targets_recursive(
    manager: BuildManager,
    graph: Graph,
    triggers: Set[str],
    deps: Dict[str, Set[str]],
    up_to_date_modules: Set[str],
) -> Tuple[Dict[str, Set[FineGrainedDeferredNode]], Set[str], Set[TypeInfo]]:
    """Find names of all targets that need to reprocessed, given some triggers.

    Returns: A tuple containing a:
     * Dictionary from module id to a set of stale targets.
     * A set of module ids for unparsed modules with stale targets.
    """
    result = {}  # type: Dict[str, Set[FineGrainedDeferredNode]]
    worklist = triggers
    processed = set()  # type: Set[str]
    stale_protos = set()  # type: Set[TypeInfo]
    unloaded_files = set()  # type: Set[str]

    # Find AST nodes corresponding to each target.
    #
    # TODO: Don't rely on a set, since the items are in an unpredictable order.
    while worklist:
        processed |= worklist
        current = worklist
        worklist = set()
        for target in current:
            if target.startswith("<"):
                worklist |= deps.get(target, set()) - processed
            else:
                module_id = module_prefix(graph, target)
                if module_id is None:
                    # Deleted module.
                    continue
                if module_id in up_to_date_modules:
                    # Already processed.
                    continue
                if (
                    module_id not in manager.modules
                    or manager.modules[module_id].is_cache_skeleton
                ):
                    # We haven't actually parsed and checked the module, so we don't have
                    # access to the actual nodes.
                    # Add it to the queue of files that need to be processed fully.
                    unloaded_files.add(module_id)
                    continue

                if module_id not in result:
                    result[module_id] = set()
                manager.log_fine_grained("process: %s" % target)
                deferred, stale_proto = lookup_target(manager, target)
                if stale_proto:
                    stale_protos.add(stale_proto)
                result[module_id].update(deferred)

    return result, unloaded_files, stale_protos