spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.25k stars 1.6k forks source link

Error when accepting suggested autocomplete 10000 / 2 #16147

Open AaronBiddle opened 3 years ago

AaronBiddle commented 3 years ago

Description

What steps will reproduce the problem?

import numpy as np
import matplotlib.pyplot as plt

N = 10000

After typing the last 0 a box shows up suggesting 10000 / 2. The error message appears if I accept the suggestion. This suggestion of 10000 / 2 is only suggested if I include the two libraries shown at the beginning.

Traceback

Traceback (most recent call last):
  File "D:\Programs\anaconda3\lib\site-packages\spyder\plugins\editor\extensions\snippets.py", line 817, in insert_snippet
    ast = build_snippet_ast(text)
  File "D:\Programs\anaconda3\lib\site-packages\spyder\utils\snippets\ast.py", line 151, in build_snippet_ast
    raise SyntaxError('Syntax Error: Expected any of the following'
SyntaxError: Syntax Error: Expected any of the following characters: ['dollar', 'name', 'int', 'case', '\\:', '\\$', 'text_pipe', '{', '\\}', '\\', '\\/', '\\,', 'symbol', 'whitespace', 'left_curly_name', ':', ':+', ':-', ':?', ',', '}', '<eof>'], got <slash, />

Versions

Dependencies


# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  1.6.0 (OK)
cookiecutter >=1.6.0          :  1.7.2 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0               :  7.22.0 (OK)
jedi =0.17.2                  :  0.17.2 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.0.1 (OK)
nbconvert >=4.0               :  6.1.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
paramiko >=2.4.0              :  2.7.2 (OK)
parso =0.7.0                  :  0.7.0 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.9.0 (OK)
pylint >=1.0                  :  2.9.5 (OK)
pyls >=0.36.2;<1.0.0          :  0.36.2 (OK)
pyls_black >=0.4.6            :  0.4.6 (OK)
pyls_spyder >=0.3.2;<0.4.0    :  0.3.2 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.1.10 (OK)
qtawesome >=1.0.2             :  1.0.2 (OK)
qtconsole >=5.1.0             :  5.1.0 (OK)
qtpy >=1.5.0                  :  1.9.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=39.0.0           :  52.0.0.post20210125 (OK)
sphinx >=0.6.6                :  4.0.2 (OK)
spyder_kernels >=2.0.4;<2.1.0 :  2.0.5 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  1.0.2 (OK)
zmq >=17                      :  20.0.0 (OK)

# Optional:
cython >=0.21                 :  0.29.24 (OK)
matplotlib >=2.0.0            :  3.3.4 (OK)
numpy >=1.7                   :  1.20.3 (OK)
pandas >=1.1.1                :  1.3.0 (OK)
scipy >=0.17.0                :  1.6.2 (OK)
sympy >=0.7.3                 :  1.8 (OK)
ccordoba12 commented 3 years ago

Hey @AaronBiddle, thanks for reporting. We'll fix this problem in our next version (5.1.1), to be released shortly.

ccordoba12 commented 3 years ago

@AaronBiddle, I'm unable to reproduce this error. Could you upload a screenshot or animated showing us how to generate the error?

You can generate the gif with the Licecap program.

AaronBiddle commented 3 years ago

The problem only occurs after importing numpy and matplotlib.pyplot, but after repeating a few times I found the problem to be intermittent. However if I don't include both libraries the suggestion of 10000 / 2 never happens. Accepting the suggestion of 10000 / 2 causes the error every time. Capture

AaronBiddle commented 3 years ago

After further testing, it seemed essential that line 1, line 2, line 3, and line 4 be exactly as above. If I have any comments or add or remove any blank lines the suggestion of 10000 / 2 will not show up. I'm not sure how these suggestions are populated. I'll include another video demonstrating this.

In this video I:

  1. Demonstrate 10000 / 2 isn't suggested
  2. Add a blank line
  3. Demonstrate 10000 / 2 is suggested
  4. Remove blank line
  5. Demonstrate 10000 / 2 isn't suggested
  6. Add a blank line
  7. Demonstrate 10000 / 2 is suggested

The space before and after the "=" sign is also relevant. It only happens when I type N{space}={space}10000.

Capture

AaronBiddle commented 3 years ago

So I discovered the problem is when a slash is remembered as a suggestion, it's easy to reproduce: Capture