Spyder: pyls-mypy messages are not displayed correctly in some cases

Created on 20 Dec 2019  路  8Comments  路  Source: spyder-ide/spyder

Related to #3045

Problem Description

Some error messages from pyls-mypy are not displayed correctly. In general it happens for complicated error messages including generic types like List[T]. As far as I can see the output form pyls-mypy is correct and contains correct string.

What steps reproduce the problem?

  1. Install pyls-mypy using pip

  2. Type the following code in spyder and observe the reported code analysis message :

from typing import List

def f(*arg : List[float]) -> float:

    a1,a2 = arg

    return a1*a2

What is the expected output? What do you see instead?

Expected output is:

Incompatible return value type (got "List[float]", expected "float")

What I see is just the end of that msg:

", expected "float")

Versions

  • Spyder version: 4.0.0
  • Python version: 3.7.3
  • Qt version: 5.12.5
  • PyQt version: 5.12.3
  • Operating System name/version: Windows 10

Dependencies

cloudpickle >=0.5.0          :  1.2.2 (OK)
pygments >=2.0               :  2.5.2 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
sphinx >=0.6.6               :  2.3.0 (OK)
pylint >=0.25                :  2.4.4 (OK)
psutil >=0.3                 :  5.6.7 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.1.1 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  None (NOK)
cython >=0.21                :  None (NOK)
IPython >=4.0                :  7.10.2 (OK)
matplotlib >=2.0.0           :  None (NOK)
pandas >=0.13.1              :  None (NOK)
numpy >=1.7                  :  None (NOK)
scipy >=0.17.0               :  None (NOK)
pyls >=0.31.2;<0.32.0        :  0.31.2 (OK)
rtree >=0.8.3                :  0.9.3 (OK)
Code Completion Bug

All 8 comments

Thanks for reporting. We'll address this as soon as we move to work in Spyder 5 (in a couple of months).

spyder/plugins/editor/widgets/codeeditor.py line 2506 is msg = msg.split(']')[-1]
Might be the cause of the problem.

If you want a quick and easy workaround insert a msg.replace("]", "&#93;") into your pyls_mypy/plugin.py

spyder/plugins/editor/widgets/codeeditor.py line 2506 is msg = msg.split(']')[-1]
Might be the cause of the problem.

Why is that the case? Could you expand on your answer so we can fix the problem in our side?

I cannot comment on the specific line of code, but if the full message reads (as stated above):

Incompatible return value type (got "List[float]", expected "float")

It will be obviously distorted by splitting on ].

Pylint as far as i can tell returns it's messages like 'message': '[{}] {}'.format(diag['symbol'], diag['message']), where the symbol is a type of short indicator text e.g. missing-docstring as this is redundant information spyder contains code to remove the [ ] part. This is done by the line mentioned above. Some of the messages returned by pyls plugins (like the exaple provided by adam) get cut in half by this line of code. To fix it on your side, i would suggest only applying the cutting line of code to messages from pylint.

Changing lines 2504 - 2506

if '[' in msg and ']' in msg:
                # Remove extra redundant info from pyling messages
                msg = msg.split(']')[-1]

To something like

if src == 'pylint' and '[' in msg and ']' in msg:
                # Remove extra redundant info from pyling messages
                msg = msg.split(']')[-1]

should do the trick imho.

Great! Thanks a lot @Richardk2n for finding the cause of this problem and @adam-urbanczyk for providing an example to understand why we're not parsing MyPy messages correctly.

@steff456, please work on this one.

Thanks @Richardk2n your fix works!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danieltomasz picture danieltomasz  路  3Comments

marianux picture marianux  路  3Comments

cchu08 picture cchu08  路  3Comments

impact27 picture impact27  路  3Comments

yogu220172 picture yogu220172  路  3Comments