Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
interpreter = jedi.Interpreter(
text[:offset], namespaces, column=cursor_column, line=cursor_line + 1)
try_jedi = True
try:
# should we check the type of the node is Error ?
try:
# jedi < 0.11
from jedi.parser.tree import ErrorLeaf
except ImportError:
# jedi >= 0.11
from parso.tree import ErrorLeaf
next_to_last_tree = interpreter._get_module().tree_node.children[-2]
completing_string = False
if isinstance(next_to_last_tree, ErrorLeaf):
completing_string = next_to_last_tree.value.lstrip()[0] in {'"', "'"}
# if we are in a string jedi is likely not the right candidate for
# now. Skip it.
try_jedi = not completing_string
except Exception as e:
# many of things can go wrong, we are using private API just don't crash.
if self.debug:
print("Error detecting if completing a non-finished string :", e, '|')
if not try_jedi:
return []
try:
return filter(completion_filter, interpreter.completions())
except Exception as e:
if self.debug:
return [_FakeJediCompletion('Oops Jedi has crashed, please report a bug with the following:\n"""\n%s\ns"""' % (e))]
def error_recovery(self, token):
if self._error_recovery:
raise NotImplementedError("Error Recovery is not implemented")
else:
type_, value, start_pos, prefix = token
error_leaf = tree.ErrorLeaf(type_, value, start_pos, prefix)
raise ParserSyntaxError('SyntaxError: invalid syntax', error_leaf)
# Python base classes
class PythonBaseNode(PythonMixin, BaseNode):
__slots__ = ()
class PythonNode(PythonMixin, Node):
__slots__ = ()
class PythonErrorNode(PythonMixin, ErrorNode):
__slots__ = ()
class PythonErrorLeaf(ErrorLeaf, PythonLeaf):
__slots__ = ()
class EndMarker(_LeafWithoutNewlines):
__slots__ = ()
type = 'endmarker'
class Newline(PythonLeaf):
"""Contains NEWLINE and ENDMARKER tokens."""
__slots__ = ()
type = 'newline'
@utf8_repr
def __repr__(self):
return "<%s: %s>" % (type(self).__name__, repr(self.value))
def __init__(self, token_type, value, start_pos, prefix=''):
super(ErrorLeaf, self).__init__(value, start_pos, prefix)
self.token_type = token_type
def error_recovery(self, token):
if self._error_recovery:
raise NotImplementedError("Error Recovery is not implemented")
else:
type_, value, start_pos, prefix = token
error_leaf = tree.ErrorLeaf('TODO %s' % type_, value, start_pos, prefix)
raise ParserSyntaxError('SyntaxError: invalid syntax', error_leaf)
# Python base classes
class PythonBaseNode(PythonMixin, BaseNode):
__slots__ = ()
class PythonNode(PythonMixin, Node):
__slots__ = ()
class PythonErrorNode(PythonMixin, ErrorNode):
__slots__ = ()
class PythonErrorLeaf(ErrorLeaf, PythonLeaf):
__slots__ = ()
class EndMarker(_LeafWithoutNewlines):
__slots__ = ()
type = 'endmarker'
@utf8_repr
def __repr__(self):
return "<%s: prefix=%s end_pos=%s>" % (
type(self).__name__, repr(self.prefix), self.end_pos
)
class Newline(PythonLeaf):
"""Contains NEWLINE and ENDMARKER tokens."""
# Python base classes
class PythonBaseNode(PythonMixin, BaseNode):
__slots__ = ()
class PythonNode(PythonMixin, Node):
__slots__ = ()
class PythonErrorNode(PythonMixin, ErrorNode):
__slots__ = ()
class PythonErrorLeaf(ErrorLeaf, PythonLeaf):
__slots__ = ()
class EndMarker(_LeafWithoutNewlines):
__slots__ = ()
type = 'endmarker'
@utf8_repr
def __repr__(self):
return "<%s: prefix=%s>" % (type(self).__name__, repr(self.prefix))
class Newline(PythonLeaf):
"""Contains NEWLINE and ENDMARKER tokens."""
__slots__ = ()
type = 'newline'