1
0
forked from VimPlug/jedi

fix a problem with dynamic flow information and usages

This commit is contained in:
David Halter
2013-07-24 01:28:15 +02:00
parent 991b138ff3
commit 972d4e9a08
4 changed files with 21 additions and 3 deletions

View File

@@ -410,6 +410,8 @@ class Script(object):
:rtype: list of :class:`api_classes.Usage`
"""
temp, settings.dynamic_flow_information = \
settings.dynamic_flow_information, False
user_stmt = self._parser.user_stmt
definitions, search_name = self._goto(add_import_name=True)
if isinstance(user_stmt, pr.Statement):
@@ -433,6 +435,7 @@ class Script(object):
else:
names.append(api_classes.Usage(d.names[-1], d))
settings.dynamic_flow_information = temp
return self._sorted_defs(set(names))
@api_classes._clear_caches_after_call

View File

@@ -505,22 +505,24 @@ def check_flow_information(flow, search_name, pos):
ensures that `k` is a string.
"""
if not settings.dynamic_flow_information:
return None
result = []
if isinstance(flow, (pr.Scope, fast_parser.Module)) and not result:
for ass in reversed(flow.asserts):
if pos is None or ass.start_pos > pos:
continue
result = check_statement_information(ass, search_name)
result = _check_isinstance_type(ass, search_name)
if result:
break
if isinstance(flow, pr.Flow) and not result:
if flow.command in ['if', 'while'] and len(flow.inputs) == 1:
result = check_statement_information(flow.inputs[0], search_name)
result = _check_isinstance_type(flow.inputs[0], search_name)
return result
def check_statement_information(stmt, search_name):
def _check_isinstance_type(stmt, search_name):
try:
commands = stmt.get_commands()
# this might be removed if we analyze and, etc

View File

@@ -175,6 +175,11 @@ Additional modules in which |jedi| checks if statements are to be found. This
is practical for IDEs, that want to administrate their modules themselves.
"""
dynamic_flow_information = True
"""
Check for `isinstance` and other information to infer a type.
"""
# ----------------
# recursions
# ----------------

View File

@@ -213,3 +213,11 @@ class TestProperty:
#< 11 (1,11), (0,8)
def f(**kwargs):
return kwargs
# -----------------
# No result
# -----------------
if isinstance(j, int):
#<
j