Skip to content

Commit

Permalink
Merge pull request #20226 from dalthviz/fixes_issue_20156
Browse files Browse the repository at this point in the history
PR: Prevent Python variable validation to get current word and position when doing completions
  • Loading branch information
ccordoba12 authored Dec 20, 2022
2 parents 6b08e97 + 1580420 commit f586c20
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 54 deletions.
53 changes: 0 additions & 53 deletions spyder/plugins/editor/widgets/tests/test_introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
# Local imports
from spyder.config.base import running_in_ci, running_in_ci_with_conda
from spyder.config.utils import is_anaconda
from spyder.plugins.completion.api import (
CompletionRequestTypes, CompletionItemKind)
from spyder.plugins.completion.providers.kite.providers.document import (
KITE_COMPLETION)
from spyder.plugins.completion.providers.kite.utils.status import (
check_if_kite_installed, check_if_kite_running)
from spyder.py3compat import PY2
Expand Down Expand Up @@ -1068,55 +1064,6 @@ def test_text_snippet_completions(completions_codeeditor, qtbot):
code_editor.toggle_code_snippets(True)


@pytest.mark.slow
@pytest.mark.order(1)
@flaky(max_runs=5)
def test_kite_textEdit_completions(mock_completions_codeeditor, qtbot):
"""Test textEdit completions such as those returned by the Kite provider.
This mocks out the completions response, and does not test the Kite
provider directly.
"""
code_editor, mock_response = mock_completions_codeeditor
completion = code_editor.completion_widget

code_editor.toggle_automatic_completions(False)
code_editor.toggle_code_snippets(False)

# Set cursor to start
code_editor.go_to_line(1)

qtbot.keyClicks(code_editor, 'my_dict.')

# Complete my_dict. -> my_dict["dict-key"]
mock_response.side_effect = lambda lang, method, params: {'params': [{
'kind': CompletionItemKind.TEXT,
'label': '["dict-key"]',
'textEdit': {
'newText': '["dict-key"]',
'range': {
'start': 7,
'end': 8,
},
},
'filterText': '',
'sortText': '',
'documentation': '',
'provider': KITE_COMPLETION,
}]} if method == CompletionRequestTypes.DOCUMENT_COMPLETION else None
with qtbot.waitSignal(completion.sig_show_completions,
timeout=10000) as sig:
qtbot.keyPress(code_editor, Qt.Key_Tab, delay=300)
mock_response.side_effect = None

assert '["dict-key"]' in [x['label'] for x in sig.args[0]]
qtbot.keyPress(code_editor, Qt.Key_Enter, delay=300)
assert code_editor.toPlainText() == 'my_dict["dict-key"]\n'

code_editor.toggle_automatic_completions(True)
code_editor.toggle_code_snippets(True)


@pytest.mark.slow
@pytest.mark.order(1)
@flaky(max_runs=5)
Expand Down
2 changes: 1 addition & 1 deletion spyder/widgets/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ def is_special_character(move):
startpos = cursor.selectionStart()

# Find a valid Python variable name
if valid_python_variable:
if valid_python_variable and not completion:
match = re.findall(r'([^\d\W]\w*)', text, re.UNICODE)
if not match:
# This is assumed in several places of our codebase,
Expand Down

0 comments on commit f586c20

Please sign in to comment.