diff --git a/pyqode/python/__init__.py b/pyqode/python/__init__.py index 754a4959..3dee597b 100644 --- a/pyqode/python/__init__.py +++ b/pyqode/python/__init__.py @@ -7,4 +7,4 @@ """ -__version__ = '2.11.1' +__version__ = '2.12.1' diff --git a/pyqode/python/backend/workers.py b/pyqode/python/backend/workers.py index 6ff02c27..e7e1aaa6 100644 --- a/pyqode/python/backend/workers.py +++ b/pyqode/python/backend/workers.py @@ -38,7 +38,14 @@ def calltips(request_data): # encoding = request_data['encoding'] encoding = 'utf-8' # use jedi to get call signatures - script = jedi.Script(code, line, column, path, encoding) + try: + script = jedi.Script(code, line, column, path, encoding) + except ValueError: + # Is triggered when an the position is invalid, for example if the + # column is larger or equal to the line length. This may be due to a + # bug elsewhere in PyQode, but this at least suppresses the error + # message, and does not seem to hve any adverse side effects. + return [] signatures = script.call_signatures() for sig in signatures: results = (str(sig.module_name), str(sig.name), @@ -315,7 +322,7 @@ def complete(code, line, column, path, encoding, prefix): script = jedi.Script(code, line + 1, column, path, encoding) completions = script.completions() print('completions: %r' % completions) - except jedi.NotFoundError: + except RuntimeError: completions = [] for completion in completions: ret_val.append({ diff --git a/pyqode/python/modes/autoindent.py b/pyqode/python/modes/autoindent.py index 4f6c0a21..69582b1c 100644 --- a/pyqode/python/modes/autoindent.py +++ b/pyqode/python/modes/autoindent.py @@ -60,7 +60,7 @@ def _get_indent(self, cursor): elif line.endswith("\\"): # if user typed \ and press enter -> indent is always # one level higher - post += self.editor.tab_length * " " + post += self._single_indent elif (fullline.endswith((')', '}', ']')) and lastword.endswith((')', '}', ']'))): post = self._handle_indent_after_paren(cursor, post) @@ -260,11 +260,11 @@ def _handle_indent_between_paren(self, column, line, parent_impl, tc): open_line_txt = self._helper.line_text(open_line) open_line_indent = len(open_line_txt) - len(open_line_txt.lstrip()) if prev_open: - post = (open_line_indent + self.editor.tab_length) * ' ' + post = open_line_indent * self._indent_char + self._single_indent elif next_close and prev_char != ',': - post = open_line_indent * ' ' + post = open_line_indent * self._indent_char elif tc.block().blockNumber() == open_line: - post = open_symbol_col * ' ' + post = open_symbol_col * self._indent_char # adapt indent if cursor on closing line and next line have same # indent -> PEP8 compliance @@ -272,12 +272,12 @@ def _handle_indent_between_paren(self, column, line, parent_impl, tc): txt = self._helper.line_text(close_line) bn = tc.block().blockNumber() flg = bn == close_line - next_indent = self._helper.line_indent(bn + 1) * ' ' + next_indent = self._helper.line_indent(bn + 1) * self._indent_char if flg and txt.strip().endswith(':') and next_indent == post: # | look at how the previous line ( ``':'):`` ) was # over-indented, this is actually what we are trying to # achieve here - post += self.editor.tab_length * ' ' + post += self._single_indent # breaking string if next_char in ['"', "'"]: @@ -319,19 +319,19 @@ def _handle_indent_inside_string(self, char, cursor, fullline, post): # break string with a '\' at the end of the original line, always # breaking strings enclosed by parens is done in the # _handle_between_paren method - n = self.editor.tab_length pre = '%s \\' % char - post += n * ' ' + post += self._single_indent if fullline.endswith(':'): - post += n * " " + post += self._single_indent post += char return post, pre def _handle_new_scope_indentation(self, cursor, fullline): try: - indent = (self._get_indent_of_opening_paren(cursor) + - self.editor.tab_length) - post = indent * " " + post = ( + self._get_indent_of_opening_paren(cursor) * self._indent_char + + self._single_indent + ) except TypeError: # e.g indent is None (meaning the line does not ends with ):, ]: # or }: @@ -349,15 +349,15 @@ def check_kw_in_line(kwds, lparam): while not check_kw_in_line(kw, l) and ln: ln -= 1 l = self._helper.line_text(ln) - indent = (len(l) - len(l.lstrip())) * " " - indent += self.editor.tab_length * " " + indent = (len(l) - len(l.lstrip())) * self._indent_char + indent += self._single_indent post = indent return post def _handle_indent_after_paren(self, cursor, post): indent = self._get_indent_of_opening_paren(cursor) if indent is not None: - post = indent * " " + post = indent * self._indent_char return post def _handle_indent_in_statement(self, fullline, lastword, post, pre): @@ -366,7 +366,7 @@ def _handle_indent_in_statement(self, fullline, lastword, post, pre): pre += " \\" else: pre += '\\' - post += self.editor.tab_length * " " + post += self._single_indent if fullline.endswith(':'): - post += self.editor.tab_length * " " + post += self._single_indent return post, pre diff --git a/pyqode/python/modes/indenter.py b/pyqode/python/modes/indenter.py index f9dcede4..3c89da3a 100644 --- a/pyqode/python/modes/indenter.py +++ b/pyqode/python/modes/indenter.py @@ -47,15 +47,7 @@ def indent(self): if cursor.hasSelection(): self.indent_selection(cursor) else: - # simply insert indentation at the cursor position - tab_len = self.editor.tab_length - cursor.beginEditBlock() - if self.editor.use_spaces_instead_of_tabs: - cursor.insertText(tab_len * " ") - else: - cursor.insertText('\t') - cursor.endEditBlock() - self.editor.setTextCursor(cursor) + cursor.insertText(self._single_indent) def unindent(self): """ @@ -63,9 +55,12 @@ def unindent(self): """ if self.tab_always_indent: cursor = self.editor.textCursor() + cursor.beginEditBlock() if not cursor.hasSelection(): cursor.select(cursor.LineUnderCursor) self.unindent_selection(cursor) + cursor.endEditBlock() + self.editor.setTextCursor(cursor) else: super(PyIndenterMode, self).unindent() diff --git a/setup.py b/setup.py index 0af39ce7..817c1111 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ def readme(): 'pyqode.qt', 'pyqode.core', 'jedi', - 'pep8', + 'pycodestyle', 'pyflakes', 'docutils' ] diff --git a/test/test_backend/test_workers.py b/test/test_backend/test_workers.py index e546cf5c..44021a18 100644 --- a/test/test_backend/test_workers.py +++ b/test/test_backend/test_workers.py @@ -72,7 +72,7 @@ def test_extract_def(): editor.show() app.exec() """ - for definition in jedi.defined_names(code): + for definition in jedi.names(code): result = workers._extract_def(definition, "") assert result