mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-19 23:09:43 +08:00
Remove the def isinstance from the parser. It was a really bad pattern.
This commit is contained in:
@@ -203,10 +203,10 @@ def _check_for_exception_catch(node_context, jedi_name, exception, payload=None)
|
|||||||
while obj is not None and not isinstance(obj, (tree.Function, tree.Class)):
|
while obj is not None and not isinstance(obj, (tree.Function, tree.Class)):
|
||||||
if isinstance(obj, tree.Flow):
|
if isinstance(obj, tree.Flow):
|
||||||
# try/except catch check
|
# try/except catch check
|
||||||
if obj.isinstance(tree.TryStmt) and check_try_for_except(obj, exception):
|
if obj.type == 'try_stmt' and check_try_for_except(obj, exception):
|
||||||
return True
|
return True
|
||||||
# hasattr check
|
# hasattr check
|
||||||
if exception == AttributeError and obj.isinstance(tree.IfStmt, tree.WhileStmt):
|
if exception == AttributeError and obj.type in ('if_stmt', 'while_stmt'):
|
||||||
if check_hasattr(obj.children[1], obj.children[3]):
|
if check_hasattr(obj.children[1], obj.children[3]):
|
||||||
return True
|
return True
|
||||||
obj = obj.parent
|
obj = obj.parent
|
||||||
|
|||||||
@@ -165,11 +165,11 @@ class NameFinder(object):
|
|||||||
def _name_to_types(evaluator, context, tree_name):
|
def _name_to_types(evaluator, context, tree_name):
|
||||||
types = []
|
types = []
|
||||||
node = tree_name.get_definition()
|
node = tree_name.get_definition()
|
||||||
if node.isinstance(tree.ForStmt):
|
if node.type == 'for_stmt':
|
||||||
types = pep0484.find_type_from_comment_hint_for(context, node, tree_name)
|
types = pep0484.find_type_from_comment_hint_for(context, node, tree_name)
|
||||||
if types:
|
if types:
|
||||||
return types
|
return types
|
||||||
if node.isinstance(tree.WithStmt):
|
if node.type == 'with_stmt':
|
||||||
types = pep0484.find_type_from_comment_hint_with(context, node, tree_name)
|
types = pep0484.find_type_from_comment_hint_with(context, node, tree_name)
|
||||||
if types:
|
if types:
|
||||||
return types
|
return types
|
||||||
@@ -180,9 +180,9 @@ def _name_to_types(evaluator, context, tree_name):
|
|||||||
container_types = context.eval_node(node.children[3])
|
container_types = context.eval_node(node.children[3])
|
||||||
for_types = iterable.py__iter__types(evaluator, container_types, node.children[3])
|
for_types = iterable.py__iter__types(evaluator, container_types, node.children[3])
|
||||||
types = check_tuple_assignments(evaluator, for_types, tree_name)
|
types = check_tuple_assignments(evaluator, for_types, tree_name)
|
||||||
elif node.isinstance(tree.ExprStmt):
|
elif node.type == 'expr_stmt':
|
||||||
types = _remove_statements(evaluator, context, node, tree_name)
|
types = _remove_statements(evaluator, context, node, tree_name)
|
||||||
elif node.isinstance(tree.WithStmt):
|
elif node.type == 'with_stmt':
|
||||||
types = context.eval_node(node.node_from_name(tree_name))
|
types = context.eval_node(node.node_from_name(tree_name))
|
||||||
elif isinstance(node, tree.Import):
|
elif isinstance(node, tree.Import):
|
||||||
types = imports.infer_import(context, tree_name)
|
types = imports.infer_import(context, tree_name)
|
||||||
|
|||||||
+4
-7
@@ -120,9 +120,6 @@ class Base(object):
|
|||||||
"""
|
"""
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def isinstance(self, *cls):
|
|
||||||
return isinstance(self, cls)
|
|
||||||
|
|
||||||
def get_root_node(self):
|
def get_root_node(self):
|
||||||
scope = self
|
scope = self
|
||||||
while scope.parent is not None:
|
while scope.parent is not None:
|
||||||
@@ -142,7 +139,7 @@ class Base(object):
|
|||||||
scope = self if include_current else self.parent
|
scope = self if include_current else self.parent
|
||||||
while scope.parent is not None:
|
while scope.parent is not None:
|
||||||
# TODO why if classes?
|
# TODO why if classes?
|
||||||
if classes and reverse != scope.isinstance(*classes):
|
if classes and reverse != isinstance(scope, classes):
|
||||||
break
|
break
|
||||||
scope = scope.parent
|
scope = scope.parent
|
||||||
return scope
|
return scope
|
||||||
@@ -166,7 +163,7 @@ class Base(object):
|
|||||||
scope = self
|
scope = self
|
||||||
while scope.parent is not None:
|
while scope.parent is not None:
|
||||||
parent = scope.parent
|
parent = scope.parent
|
||||||
if scope.isinstance(Node, Leaf) and parent.type != 'simple_stmt':
|
if isinstance(scope, (Node, Leaf)) and parent.type != 'simple_stmt':
|
||||||
if scope.type == 'testlist_comp':
|
if scope.type == 'testlist_comp':
|
||||||
try:
|
try:
|
||||||
if isinstance(scope.children[1], CompFor):
|
if isinstance(scope.children[1], CompFor):
|
||||||
@@ -608,9 +605,9 @@ class BaseNode(Base):
|
|||||||
after the node, including the #
|
after the node, including the #
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if self.isinstance(ForStmt):
|
if self.type == 'for_stmt':
|
||||||
whitespace = self.children[5].first_leaf().prefix
|
whitespace = self.children[5].first_leaf().prefix
|
||||||
elif self.isinstance(WithStmt):
|
elif self.type == 'with_stmt':
|
||||||
whitespace = self.children[3].first_leaf().prefix
|
whitespace = self.children[3].first_leaf().prefix
|
||||||
else:
|
else:
|
||||||
whitespace = self.last_leaf().get_next_leaf().prefix
|
whitespace = self.last_leaf().get_next_leaf().prefix
|
||||||
|
|||||||
Reference in New Issue
Block a user