|
2 | 2 |
|
3 | 3 | import re |
4 | 4 |
|
5 | | -from typing import Set |
6 | | - |
7 | 5 | from mypy import build |
8 | 6 | from mypy.build import BuildSource |
9 | 7 | from mypy.test.config import test_temp_dir |
10 | 8 | from mypy.test.data import DataDrivenTestCase, DataSuite |
11 | 9 | from mypy.test.helpers import assert_string_arrays_equal |
| 10 | +from mypy.test.visitors import SkippedNodeSearcher, ignore_node |
12 | 11 | from mypy.util import short_type |
13 | 12 | from mypy.nodes import ( |
14 | 13 | NameExpr, TypeVarExpr, CallExpr, Expression, MypyFile, AssignmentStmt, IntExpr |
15 | 14 | ) |
16 | | -from mypy.traverser import TraverserVisitor |
17 | 15 | from mypy.errors import CompileError |
18 | 16 | from mypy.options import Options |
19 | 17 |
|
@@ -73,49 +71,3 @@ def run_case(self, testcase: DataDrivenTestCase) -> None: |
73 | 71 | testcase.output, a, |
74 | 72 | 'Invalid type checker output ({}, line {})'.format(testcase.file, |
75 | 73 | testcase.line)) |
76 | | - |
77 | | - |
78 | | -class SkippedNodeSearcher(TraverserVisitor): |
79 | | - def __init__(self) -> None: |
80 | | - self.nodes = set() # type: Set[Expression] |
81 | | - self.is_typing = False |
82 | | - |
83 | | - def visit_mypy_file(self, f: MypyFile) -> None: |
84 | | - self.is_typing = f.fullname() == 'typing' or f.fullname() == 'builtins' |
85 | | - super().visit_mypy_file(f) |
86 | | - |
87 | | - def visit_assignment_stmt(self, s: AssignmentStmt) -> None: |
88 | | - if s.type or ignore_node(s.rvalue): |
89 | | - for lvalue in s.lvalues: |
90 | | - if isinstance(lvalue, NameExpr): |
91 | | - self.nodes.add(lvalue) |
92 | | - super().visit_assignment_stmt(s) |
93 | | - |
94 | | - def visit_name_expr(self, n: NameExpr) -> None: |
95 | | - self.skip_if_typing(n) |
96 | | - |
97 | | - def visit_int_expr(self, n: IntExpr) -> None: |
98 | | - self.skip_if_typing(n) |
99 | | - |
100 | | - def skip_if_typing(self, n: Expression) -> None: |
101 | | - if self.is_typing: |
102 | | - self.nodes.add(n) |
103 | | - |
104 | | - |
105 | | -def ignore_node(node: Expression) -> bool: |
106 | | - """Return True if node is to be omitted from test case output.""" |
107 | | - |
108 | | - # We want to get rid of object() expressions in the typing module stub |
109 | | - # and also TypeVar(...) expressions. Since detecting whether a node comes |
110 | | - # from the typing module is not easy, we just to strip them all away. |
111 | | - if isinstance(node, TypeVarExpr): |
112 | | - return True |
113 | | - if isinstance(node, NameExpr) and node.fullname == 'builtins.object': |
114 | | - return True |
115 | | - if isinstance(node, NameExpr) and node.fullname == 'builtins.None': |
116 | | - return True |
117 | | - if isinstance(node, CallExpr) and (ignore_node(node.callee) or |
118 | | - node.analyzed): |
119 | | - return True |
120 | | - |
121 | | - return False |
0 commit comments