Fix: flow analysis crashed when using in combination with different modules.

This commit is contained in:
Dave Halter
2015-12-17 12:37:26 +01:00
parent 3d79d0994e
commit 54b1b2be74
4 changed files with 28 additions and 2 deletions

View File

@@ -72,9 +72,14 @@ def _break_check(evaluator, stmt, base_scope, element_scope):
if reachable in (UNREACHABLE, UNSURE):
return reachable
if element_scope.type == 'file_input':
# The definition is in another module and therefore just return what we
# have generated.
return reachable
if base_scope != element_scope and base_scope != element_scope.parent:
return reachable & _break_check(evaluator, stmt, base_scope, element_scope.parent)
return reachable
else:
return reachable
def _check_if(evaluator, node):

View File

@@ -238,3 +238,20 @@ else:
s = str()
#? str()
possible_recursion_error(s)
# -----------------
# In combination with imports
# -----------------
from import_tree import flow_import
if 1 == flow_import.env:
a = 1
elif 2 == flow_import.env:
a = ''
elif 3 == flow_import.env:
a = 1.0
#? int() str()
a

View File

@@ -0,0 +1,4 @@
if name:
env = 1
else:
env = 2

View File

@@ -65,7 +65,7 @@ import datetime.date
from import_tree.pkg import pkg
#? 22 ['mod1']
from import_tree.pkg. import mod1
#? 17 ['mod1', 'mod2', 'random', 'pkg', 'rename1', 'rename2', 'recurse_class1', 'recurse_class2', 'invisible_pkg']
#? 17 ['mod1', 'mod2', 'random', 'pkg', 'rename1', 'rename2', 'recurse_class1', 'recurse_class2', 'invisible_pkg', 'flow_import']
from import_tree. import pkg
#? 18 ['pkg']