diff --git a/jedi/debug.py b/jedi/debug.py index e67cec27..692f9c82 100644 --- a/jedi/debug.py +++ b/jedi/debug.py @@ -86,14 +86,9 @@ def increase_indent(func): def dbg(message, *args, **kwargs): """ 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 - # after *args. - color = kwargs.get('color') - if color is None: - raise TypeError("debug.dbg doesn't support more named arguments than color") - else: - color = 'GREEN' + # Python 2 compatibility, because it doesn't understand default args + color = kwargs.pop('color', 'GREEN') + assert color if debug_function and enable_notice: 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)) -def warning(message, *args): +def warning(message, *args, **kwargs): + format = kwargs.pop('format', True) + assert not kwargs + if debug_function and enable_warning: 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): diff --git a/jedi/evaluate/analysis.py b/jedi/evaluate/analysis.py index 7b4b0acc..407bc7da 100644 --- a/jedi/evaluate/analysis.py +++ b/jedi/evaluate/analysis.py @@ -91,7 +91,7 @@ def add(evaluator, name, jedi_obj, message=None, typ=Error, payload=None): module_path = jedi_obj.get_parent_until().path instance = typ(name, module_path, jedi_obj.start_pos, message) - debug.warning(str(instance)) + debug.warning(str(instance), format=False) evaluator.analysis.append(instance) diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index acbd7b08..79a1a0e2 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -181,8 +181,15 @@ class Comprehension(IterableWrapper): """ comp_for = self._get_comp_for() # 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] - 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): 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 compatibility reasons, we're now using kwargs. """ - sequence_type = kwargs['sequence_type'] - del kwargs['sequence_type'] + sequence_type = kwargs.pop('sequence_type') assert not kwargs sets = tuple(AlreadyEvaluated(types) for types in types_order) diff --git a/test/completion/comprehensions.py b/test/completion/comprehensions.py index 19feb7e7..a0a709c7 100644 --- a/test/completion/comprehensions.py +++ b/test/completion/comprehensions.py @@ -181,3 +181,20 @@ def x(): foo = [x for x in [1, '']][:1] #? int() 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()