Skip to content

Commit ffb3ce9

Browse files
authored
Add tests for new semantic analyzer on older Python (#6640)
This also fixes minor issues found by tests
1 parent 486e4d7 commit ffb3ce9

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ jobs:
2222
python: 3.6 # 3.6.3 pip 9.0.1
2323
- name: "run test suite with python 3.7"
2424
python: 3.7 # 3.7.0 pip 10.0.1
25+
- name: "run test suite with python 3.5.1 (new semantic analyzer)"
26+
python: 3.5.1
27+
dist: trusty
28+
env:
29+
- TOXENV=py
30+
- EXTRA_ARGS="-n 12"
31+
- NEWSEMANAL=1
2532
- name: "run test suite with python 3.7 (new semantic analyzer)"
2633
python: 3.7
2734
env:

mypy/newsemanal/semanal_main.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ def process_functions(graph: 'Graph', scc: List[str], patches: Patches) -> None:
182182
tree = graph[module].tree
183183
assert tree is not None
184184
analyzer = graph[module].manager.new_semantic_analyzer
185-
targets = get_all_leaf_targets(tree)
185+
# In principle, functions can be processed in arbitrary order,
186+
# but _methods_ must be processed in the order they are defined,
187+
# because some features (most notably partial types) depend on
188+
# order of definitions on self.
189+
targets = sorted(get_all_leaf_targets(tree), key=lambda x: x[1].line)
186190
for target, node, active_type in targets:
187191
assert isinstance(node, (FuncDef, OverloadedFuncDef, Decorator))
188192
process_top_level_function(analyzer,

mypy/server/aststripnew.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
FuncDef, NameExpr, MemberExpr, RefExpr, MypyFile, ClassDef, AssignmentStmt,
1111
ImportFrom, CallExpr, Decorator, OverloadedFuncDef, Node, TupleExpr, ListExpr,
1212
SuperExpr, IndexExpr, ImportAll, ForStmt, Block, CLASSDEF_NO_INFO, TypeInfo,
13-
StarExpr, Var
13+
StarExpr, Var, SymbolTableNode
1414
)
1515
from mypy.traverser import TraverserVisitor
1616
from mypy.types import CallableType
@@ -87,7 +87,9 @@ def prepare_implicit_var_patches(self, node: ClassDef) -> None:
8787
if isinstance(sym.node, Var) and sym.implicit:
8888
explicit_self_type = sym.node.explicit_self_type
8989

90-
def patch() -> None:
90+
# These arguments should not be passed, we just want to capture
91+
# the names in closure at current iteration in the for-loop.
92+
def patch(name: str = name, sym: SymbolTableNode = sym) -> None:
9193
existing = node.info.get(name)
9294
defined_in_this_class = name in node.info.names
9395
# This needs to mimic the logic in SemanticAnalyzer.analyze_member_lvalue()

0 commit comments

Comments
 (0)