Commit 5c848acb authored by Tzer-jen Wei's avatar Tzer-jen Wei

can handle conflicting types now

parent 46441912
...@@ -84,7 +84,7 @@ class TestJediTyper(TransformTest): ...@@ -84,7 +84,7 @@ class TestJediTyper(TransformTest):
self.assertFalse(types) self.assertFalse(types)
self.assertEqual({'a': set(['int']), 'i': set(['int'])}, variables) self.assertEqual({'a': set(['int']), 'i': set(['int'])}, variables)
def _test_conflicting_types_in_function(self): def test_conflicting_types_in_function(self):
code = '''\ code = '''\
def func(a, b): def func(a, b):
print(a) print(a)
...@@ -99,7 +99,7 @@ class TestJediTyper(TransformTest): ...@@ -99,7 +99,7 @@ class TestJediTyper(TransformTest):
self.assertIn(('func', (1, 0)), types) self.assertIn(('func', (1, 0)), types)
variables = types.pop(('func', (1, 0))) variables = types.pop(('func', (1, 0)))
self.assertFalse(types) self.assertFalse(types)
self.assertEqual({'a': set(['int', 'str']), 'i': set(['int'])}, variables) self.assertEqual({'a': set(['float', 'int', 'str']), 'b': set(['int'])}, variables)
def _test_typing_function_char_loop(self): def _test_typing_function_char_loop(self):
code = '''\ code = '''\
......
...@@ -44,9 +44,11 @@ def analyse(source_path=None, code=None): ...@@ -44,9 +44,11 @@ def analyse(source_path=None, code=None):
try: try:
names = scoped_names[key] names = scoped_names[key]
except KeyError: except KeyError:
names = scoped_names[key] = defaultdict(set) names = scoped_names[key] = defaultdict(set)
position = statement.start_pos if statement.name in names else None
for name_type in evaluator.find_types(scope, statement.name, search_global=True): for name_type in evaluator.find_types(scope, statement.name, position=position ,search_global=True):
if isinstance(name_type, Instance): if isinstance(name_type, Instance):
if isinstance(name_type.base, Class): if isinstance(name_type.base, Class):
type_name = 'object' type_name = 'object'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment