コード例 #1
0
ファイル: testgraph.py プロジェクト: lslaoang/mypy
 def test_sorted_components(self) -> None:
     manager = self._make_manager()
     graph = {'a': State('a', None, 'import b, c', manager),
              'd': State('d', None, 'pass', manager),
              'b': State('b', None, 'import c', manager),
              'c': State('c', None, 'import b, d', manager),
              }
     res = sorted_components(graph)
     assert_equal(res, [frozenset({'d'}), frozenset({'c', 'b'}), frozenset({'a'})])
コード例 #2
0
ファイル: testgraph.py プロジェクト: lslaoang/mypy
 def test_order_ascc(self) -> None:
     manager = self._make_manager()
     graph = {'a': State('a', None, 'import b, c', manager),
              'd': State('d', None, 'def f(): import a', manager),
              'b': State('b', None, 'import c', manager),
              'c': State('c', None, 'import b, d', manager),
              }
     res = sorted_components(graph)
     assert_equal(res, [frozenset({'a', 'd', 'c', 'b'})])
     ascc = res[0]
     scc = order_ascc(graph, ascc)
     assert_equal(scc, ['d', 'c', 'b', 'a'])
コード例 #3
0
ファイル: testgraph.py プロジェクト: truepositiontruefix/mypy
 def test_sorted_components(self) -> None:
     manager = BuildManager(data_dir='',
                            lib_path=[],
                            target=TYPE_CHECK,
                            pyversion=(3, 5),
                            flags=[],
                            ignore_prefix='',
                            custom_typing_module='',
                            source_set=None,
                            reports=None)
     graph = {
         'a': State('a', None, 'import b, c', manager),
         'b': State('b', None, 'import c', manager),
         'c': State('c', None, 'import b, d', manager),
         'd': State('d', None, 'pass', manager)
     }
     res = sorted_components(graph)
     assert_equal(
         res, [frozenset({'d'}),
               frozenset({'c', 'b'}),
               frozenset({'a'})])
コード例 #4
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}
コード例 #5
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