mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
More comprehension issues.
This commit is contained in:
@@ -86,14 +86,9 @@ def increase_indent(func):
|
|||||||
|
|
||||||
def dbg(message, *args, **kwargs):
|
def dbg(message, *args, **kwargs):
|
||||||
""" Looks at the stack, to see if a debug message should be printed. """
|
""" Looks at the stack, to see if a debug message should be printed. """
|
||||||
if kwargs:
|
|
||||||
# Python 2 compatibility, because it doesn't understand default args
|
# Python 2 compatibility, because it doesn't understand default args
|
||||||
# after *args.
|
color = kwargs.pop('color', 'GREEN')
|
||||||
color = kwargs.get('color')
|
assert color
|
||||||
if color is None:
|
|
||||||
raise TypeError("debug.dbg doesn't support more named arguments than color")
|
|
||||||
else:
|
|
||||||
color = 'GREEN'
|
|
||||||
|
|
||||||
if debug_function and enable_notice:
|
if debug_function and enable_notice:
|
||||||
frm = inspect.stack()[1]
|
frm = inspect.stack()[1]
|
||||||
@@ -104,10 +99,15 @@ def dbg(message, *args, **kwargs):
|
|||||||
debug_function(color, i + 'dbg: ' + message % tuple(u(repr(a)) for a in args))
|
debug_function(color, i + 'dbg: ' + message % tuple(u(repr(a)) for a in args))
|
||||||
|
|
||||||
|
|
||||||
def warning(message, *args):
|
def warning(message, *args, **kwargs):
|
||||||
|
format = kwargs.pop('format', True)
|
||||||
|
assert not kwargs
|
||||||
|
|
||||||
if debug_function and enable_warning:
|
if debug_function and enable_warning:
|
||||||
i = ' ' * _debug_indent
|
i = ' ' * _debug_indent
|
||||||
debug_function('RED', i + 'warning: ' + message % tuple(u(repr(a)) for a in args))
|
if format:
|
||||||
|
message = message % tuple(u(repr(a)) for a in args)
|
||||||
|
debug_function('RED', i + 'warning: ' + message)
|
||||||
|
|
||||||
|
|
||||||
def speed(name):
|
def speed(name):
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ def add(evaluator, name, jedi_obj, message=None, typ=Error, payload=None):
|
|||||||
|
|
||||||
module_path = jedi_obj.get_parent_until().path
|
module_path = jedi_obj.get_parent_until().path
|
||||||
instance = typ(name, module_path, jedi_obj.start_pos, message)
|
instance = typ(name, module_path, jedi_obj.start_pos, message)
|
||||||
debug.warning(str(instance))
|
debug.warning(str(instance), format=False)
|
||||||
evaluator.analysis.append(instance)
|
evaluator.analysis.append(instance)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -181,8 +181,15 @@ class Comprehension(IterableWrapper):
|
|||||||
"""
|
"""
|
||||||
comp_for = self._get_comp_for()
|
comp_for = self._get_comp_for()
|
||||||
# For nested comprehensions we need to search the last one.
|
# For nested comprehensions we need to search the last one.
|
||||||
|
from jedi.evaluate.representation import InstanceElement
|
||||||
|
node = self._get_comprehension().children[index]
|
||||||
|
if isinstance(node, InstanceElement):
|
||||||
|
# This seems to be a strange case that I haven't found a way to
|
||||||
|
# write tests against. However since it's my new goal to get rid of
|
||||||
|
# InstanceElement anyway, I don't care.
|
||||||
|
node = node.var
|
||||||
last_comp = list(comp_for.get_comp_fors())[-1]
|
last_comp = list(comp_for.get_comp_fors())[-1]
|
||||||
return helpers.deep_ast_copy(self._get_comprehension().children[index], parent=last_comp)
|
return helpers.deep_ast_copy(node, parent=last_comp)
|
||||||
|
|
||||||
def _nested(self, comp_fors):
|
def _nested(self, comp_fors):
|
||||||
evaluator = self._evaluator
|
evaluator = self._evaluator
|
||||||
@@ -453,8 +460,7 @@ def create_evaluated_sequence_set(evaluator, *types_order, **kwargs):
|
|||||||
``sequence_type`` is a named argument, that doesn't work in Python2. For backwards
|
``sequence_type`` is a named argument, that doesn't work in Python2. For backwards
|
||||||
compatibility reasons, we're now using kwargs.
|
compatibility reasons, we're now using kwargs.
|
||||||
"""
|
"""
|
||||||
sequence_type = kwargs['sequence_type']
|
sequence_type = kwargs.pop('sequence_type')
|
||||||
del kwargs['sequence_type']
|
|
||||||
assert not kwargs
|
assert not kwargs
|
||||||
|
|
||||||
sets = tuple(AlreadyEvaluated(types) for types in types_order)
|
sets = tuple(AlreadyEvaluated(types) for types in types_order)
|
||||||
|
|||||||
@@ -181,3 +181,20 @@ def x():
|
|||||||
foo = [x for x in [1, '']][:1]
|
foo = [x for x in [1, '']][:1]
|
||||||
#? int()
|
#? int()
|
||||||
foo[0]
|
foo[0]
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# In class
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
class X():
|
||||||
|
def __init__(self, bar):
|
||||||
|
self.bar = bar
|
||||||
|
|
||||||
|
def foo(self):
|
||||||
|
x = [a for a in self.bar][0]
|
||||||
|
#? int()
|
||||||
|
x
|
||||||
|
return x
|
||||||
|
|
||||||
|
#? int()
|
||||||
|
X([1]).foo()
|
||||||
|
|||||||
Reference in New Issue
Block a user