forked from VimPlug/jedi
fix a problem with dynamic flow information and usages
This commit is contained in:
@@ -410,6 +410,8 @@ class Script(object):
|
|||||||
|
|
||||||
:rtype: list of :class:`api_classes.Usage`
|
:rtype: list of :class:`api_classes.Usage`
|
||||||
"""
|
"""
|
||||||
|
temp, settings.dynamic_flow_information = \
|
||||||
|
settings.dynamic_flow_information, False
|
||||||
user_stmt = self._parser.user_stmt
|
user_stmt = self._parser.user_stmt
|
||||||
definitions, search_name = self._goto(add_import_name=True)
|
definitions, search_name = self._goto(add_import_name=True)
|
||||||
if isinstance(user_stmt, pr.Statement):
|
if isinstance(user_stmt, pr.Statement):
|
||||||
@@ -433,6 +435,7 @@ class Script(object):
|
|||||||
else:
|
else:
|
||||||
names.append(api_classes.Usage(d.names[-1], d))
|
names.append(api_classes.Usage(d.names[-1], d))
|
||||||
|
|
||||||
|
settings.dynamic_flow_information = temp
|
||||||
return self._sorted_defs(set(names))
|
return self._sorted_defs(set(names))
|
||||||
|
|
||||||
@api_classes._clear_caches_after_call
|
@api_classes._clear_caches_after_call
|
||||||
|
|||||||
@@ -505,22 +505,24 @@ def check_flow_information(flow, search_name, pos):
|
|||||||
|
|
||||||
ensures that `k` is a string.
|
ensures that `k` is a string.
|
||||||
"""
|
"""
|
||||||
|
if not settings.dynamic_flow_information:
|
||||||
|
return None
|
||||||
result = []
|
result = []
|
||||||
if isinstance(flow, (pr.Scope, fast_parser.Module)) and not result:
|
if isinstance(flow, (pr.Scope, fast_parser.Module)) and not result:
|
||||||
for ass in reversed(flow.asserts):
|
for ass in reversed(flow.asserts):
|
||||||
if pos is None or ass.start_pos > pos:
|
if pos is None or ass.start_pos > pos:
|
||||||
continue
|
continue
|
||||||
result = check_statement_information(ass, search_name)
|
result = _check_isinstance_type(ass, search_name)
|
||||||
if result:
|
if result:
|
||||||
break
|
break
|
||||||
|
|
||||||
if isinstance(flow, pr.Flow) and not result:
|
if isinstance(flow, pr.Flow) and not result:
|
||||||
if flow.command in ['if', 'while'] and len(flow.inputs) == 1:
|
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
|
return result
|
||||||
|
|
||||||
|
|
||||||
def check_statement_information(stmt, search_name):
|
def _check_isinstance_type(stmt, search_name):
|
||||||
try:
|
try:
|
||||||
commands = stmt.get_commands()
|
commands = stmt.get_commands()
|
||||||
# this might be removed if we analyze and, etc
|
# this might be removed if we analyze and, etc
|
||||||
|
|||||||
@@ -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.
|
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
|
# recursions
|
||||||
# ----------------
|
# ----------------
|
||||||
|
|||||||
@@ -213,3 +213,11 @@ class TestProperty:
|
|||||||
#< 11 (1,11), (0,8)
|
#< 11 (1,11), (0,8)
|
||||||
def f(**kwargs):
|
def f(**kwargs):
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# No result
|
||||||
|
# -----------------
|
||||||
|
if isinstance(j, int):
|
||||||
|
#<
|
||||||
|
j
|
||||||
|
|||||||
Reference in New Issue
Block a user