示例#1
0
def build_incremental_step(
    manager: BuildManager, changed_modules: List[str]
) -> Tuple[Dict[str, MypyFile], Dict[str, Dict[Expression, Type]]]:
    """Build new versions of changed modules only.

    Return the new ASTs for the changed modules. They will be totally
    separate from the existing ASTs and need to merged afterwards.
    """
    assert len(changed_modules) == 1
    id = changed_modules[0]
    path = manager.modules[id].path

    # TODO: what if file is missing?
    with open(path) as f:
        source = f.read()

    state = State(id=id, path=path, source=source,
                  manager=manager)  # TODO: more args?
    state.parse_file()
    # TODO: state.fix_suppressed_dependencies()?
    state.semantic_analysis()
    state.semantic_analysis_pass_three()
    # TODO: state.semantic_analysis_apply_patches()
    state.type_check_first_pass()
    # TODO: state.type_check_second_pass()?
    state.finish_passes()
    # TODO: state.write_cache()?
    # TODO: state.mark_as_rechecked()?

    assert state.tree is not None, "file must be at least parsed"
    return {id: state.tree}, {id: state.type_checker.type_map}
示例#2
0
文件: update.py 项目: nehaljwani/mypy
def build_incremental_step(manager: BuildManager, changed_modules: List[str],
                           graph: Dict[str, State]) -> Dict[str, MypyFile]:
    """Build new versions of changed modules only.

    Return the new ASTs for the changed modules.
    """
    assert len(changed_modules) == 1
    id = changed_modules[0]
    path = manager.modules[id].path
    old_modules = dict(manager.modules)

    # TODO: what if file is missing?
    with open(path) as f:
        source = f.read()

    state = State(id=id, path=path, source=source,
                  manager=manager)  # TODO: more args?
    # Parse file and run first pass of semantic analysis.
    state.parse_file()

    # TODO: state.fix_suppressed_dependencies()?

    # Run remaining passes of semantic analysis.
    state.semantic_analysis()
    state.semantic_analysis_pass_three()
    # TODO: state.semantic_analysis_apply_patches()

    # Merge old and new ASTs.
    assert state.tree is not None, "file must be at least parsed"
    new_modules = {id: state.tree}
    replace_modules_with_new_variants(manager, graph, old_modules, new_modules)

    # Perform type checking.
    state.type_check_first_pass()
    # TODO: state.type_check_second_pass()?
    state.finish_passes()
    # TODO: state.write_cache()?
    # TODO: state.mark_as_rechecked()?

    # Record the new types of expressions.
    graph[id].type_checker.type_map = state.type_checker.type_map

    return new_modules