mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-24 17:28:36 +08:00
Fix assertion/isinstance type information.
This commit is contained in:
+2
-16
@@ -439,11 +439,11 @@ def check_flow_information(evaluator, flow, search_name_part, pos):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
if False and flow.is_scope():
|
if flow.is_scope():
|
||||||
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_isinstance_type(evaluator, ass, search_name_part)
|
result = _check_isinstance_type(evaluator, ass.assertion(), search_name_part)
|
||||||
if result:
|
if result:
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -473,20 +473,6 @@ def _check_isinstance_type(evaluator, element, search_name):
|
|||||||
# Do a simple get_code comparison. They should just have the same code,
|
# Do a simple get_code comparison. They should just have the same code,
|
||||||
# and everything will be all right.
|
# and everything will be all right.
|
||||||
classes = lst[1][1][0]
|
classes = lst[1][1][0]
|
||||||
"""
|
|
||||||
assert arglist.type == 'arglist' and len(arglist.children) in (3, 4)
|
|
||||||
isinst = call.next.values
|
|
||||||
assert len(isinst) == 2 # has two params
|
|
||||||
obj, classes = [statement.expression_list() for statement in isinst]
|
|
||||||
assert len(obj) == 1
|
|
||||||
assert len(classes) == 1
|
|
||||||
assert isinstance(obj[0], pr.Call)
|
|
||||||
|
|
||||||
while prev.previous is not None:
|
|
||||||
prev = prev.previous
|
|
||||||
assert obj[0].get_code() == prev.get_code()
|
|
||||||
assert isinstance(classes[0], pr.StatementElement) # can be type or tuple
|
|
||||||
"""
|
|
||||||
call = helpers.call_of_name(search_name)
|
call = helpers.call_of_name(search_name)
|
||||||
assert name.get_code() == call.get_code()
|
assert name.get_code() == call.get_code()
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class Parser(object):
|
|||||||
'pass_stmt': pt.KeywordStatement,
|
'pass_stmt': pt.KeywordStatement,
|
||||||
'global_stmt': pt.GlobalStmt,
|
'global_stmt': pt.GlobalStmt,
|
||||||
'nonlocal_stmt': pt.KeywordStatement,
|
'nonlocal_stmt': pt.KeywordStatement,
|
||||||
'assert_stmt': pt.KeywordStatement,
|
'assert_stmt': pt.AssertStmt,
|
||||||
'if_stmt': pt.IfStmt,
|
'if_stmt': pt.IfStmt,
|
||||||
'with_stmt': pt.WithStmt,
|
'with_stmt': pt.WithStmt,
|
||||||
'for_stmt': pt.ForStmt,
|
'for_stmt': pt.ForStmt,
|
||||||
|
|||||||
+14
-4
@@ -468,12 +468,11 @@ class Scope(Simple, DocstringMixin):
|
|||||||
:param start_pos: The position (line and column) of the scope.
|
:param start_pos: The position (line and column) of the scope.
|
||||||
:type start_pos: tuple(int, int)
|
:type start_pos: tuple(int, int)
|
||||||
"""
|
"""
|
||||||
__slots__ = ('_doc_token', 'asserts', 'names_dict')
|
__slots__ = ('_doc_token', 'names_dict')
|
||||||
|
|
||||||
def __init__(self, children):
|
def __init__(self, children):
|
||||||
super(Scope, self).__init__(children)
|
super(Scope, self).__init__(children)
|
||||||
self._doc_token = None
|
self._doc_token = None
|
||||||
self.asserts = []
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def returns(self):
|
def returns(self):
|
||||||
@@ -481,6 +480,12 @@ class Scope(Simple, DocstringMixin):
|
|||||||
# returns will be in "normal" modules.
|
# returns will be in "normal" modules.
|
||||||
return self._search_in_scope(ReturnStmt)
|
return self._search_in_scope(ReturnStmt)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def asserts(self):
|
||||||
|
# Needed here for fast_parser, because the fast_parser splits and
|
||||||
|
# returns will be in "normal" modules.
|
||||||
|
return self._search_in_scope(AssertStmt)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def subscopes(self):
|
def subscopes(self):
|
||||||
return self._search_in_scope(Scope)
|
return self._search_in_scope(Scope)
|
||||||
@@ -1095,12 +1100,17 @@ class KeywordStatement(Simple):
|
|||||||
return self.children[0].value
|
return self.children[0].value
|
||||||
|
|
||||||
|
|
||||||
class GlobalStmt(Simple):
|
class AssertStmt(KeywordStatement):
|
||||||
|
def assertion(self):
|
||||||
|
return self.children[1]
|
||||||
|
|
||||||
|
|
||||||
|
class GlobalStmt(KeywordStatement):
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
return self.children[1::2]
|
return self.children[1::2]
|
||||||
|
|
||||||
|
|
||||||
class ReturnStmt(Simple):
|
class ReturnStmt(KeywordStatement):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user