emacs-lsp / lsp-pyright

lsp-mode :heart: pyright
https://emacs-lsp.github.io/lsp-pyright
GNU General Public License v3.0
291 stars 25 forks source link

lsp pyright errors #30

Open sdorof1 opened 4 years ago

sdorof1 commented 4 years ago

For the next code (which runs without errors):

import numpy as np
print (np.sign(-1))

I got the error with pyright in emacs:

"sign" is not a known member of module (lsp)

But if I run pyright in the shell, it doesn't report any errors:

$ pyright pyr.py 
No configuration file found.
stubPath /home/sd/pyr/typings is not a valid directory.
Assuming Python platform Linux
Searching for source files
Found 1 source file
0 errors, 0 warnings, 0 infos 
Completed in 0.551sec

So, I get a some mystic error report. This is also in other cases, for example, when work with pandas, when no pyright itself, no vscode doesn't reports any errors.

The value of lsp-pyright-typechecking-mode is basic for all cases.

seagle0128 commented 4 years ago

Is the numpy lib in pyright path? Check lsp-pyright-extra-paths or extraPaths in pyrightconfig.json? See https://github.com/microsoft/pyright/blob/master/docs/configuration.md.

sdorof1 commented 4 years ago

Is the numpy lib in pyright path? Check lsp-pyright-extra-paths or extraPaths in pyrightconfig.json?

I added the next pyrightconfig.json to project folder:

{
  "executionEnvironments": [
    {
      "root": "src"
      "extraPaths": [
         "~/.pyenv/versions/3.8.1/lib/python3.8/site-packages/"
      ]
    }
  ]
}

but without any effect. And I'm confused of need such configuration because numpy is not an some extra but as a rule system lib. It is available on python path and the program works correctly both from shell and emacs. Did I understand you correctly about configuration?

I still can get some correct information from lsp:

Снимок экрана от 2020-10-22 00-41-46

And code completion somehow works but not all functions are displayed:

Снимок экрана от 2020-10-22 01-00-26

So, seems the library is available in some part.

zeronone commented 4 years ago

Please pass in the --lib option when running from the shell.

On Thu, Oct 22, 2020, 7:07 AM sdorof1 notifications@github.com wrote:

Is the numpy lib in pyright path? Check lsp-pyright-extra-paths or extraPaths in pyrightconfig.json?

I added the next pyrightconfig.json to project folder:

{

"executionEnvironments": [

{

  "root": "src"

  "extraPaths": [

     "~/.pyenv/versions/3.8.1/lib/python3.8/site-packages/"

  ]

}

]

}

but without any effect. And I'm confused of need such configuration because numpy is not an some extra but as a rule system lib. It is available on python path and the program works correctly both from shell and emacs. Did I understand you correctly about configuration?

I still can get some correct information from lsp:

[image: Снимок экрана от 2020-10-22 00-41-46] https://user-images.githubusercontent.com/6806825/96791708-9ad36480-1401-11eb-9bf8-2b81434fa937.png

And code completion somehow works but not all functions are displayed:

[image: Снимок экрана от 2020-10-22 01-00-26] https://user-images.githubusercontent.com/6806825/96791903-00bfec00-1402-11eb-8088-bbf927072b0a.png

So, seems the library is available in some part.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/emacs-lsp/lsp-pyright/issues/30#issuecomment-713904539, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOSBAJP5UWG4CIEQ52TVOLSL5LR7ANCNFSM4SY5MXOA .

sdorof1 commented 4 years ago

Please pass in the --lib option when running from the shell.

If you mean pyright then it works from shell as expected.

zeronone commented 4 years ago

I meant we enable useLibraryCodeForTyoes by default. If you want to get same results when running pyright from the shell, you also need to pass in the --lib option.

Could you share the output when passing in the --lib option?

On Thu, Oct 22, 2020, 8:23 AM sdorof1 notifications@github.com wrote:

Please pass in the --lib option when running from the shell.

If you mean pyright then it works from shell as expected.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/emacs-lsp/lsp-pyright/issues/30#issuecomment-713967621, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOSBALHCGJF2FU52O43MT3SL5UPRANCNFSM4SY5MXOA .

sdorof1 commented 4 years ago

Could you share the output when passing in the --lib option?

Yes, I got it

pyr$ pyright --lib
  4:11 - error: "sign" is not a known member of module (reportGeneralTypeIssues)
1 error, 0 warnings, 0 infos 

Should I just disable useLibraryCodeForTyoes or there is some config that should be done?

zeronone commented 4 years ago

Disabling useLibraryCodeForTypes will also disable auto-completion for numpy. You might want to filter errors (like unknown member etc) for your project.

orlandini commented 3 years ago

@zeronone how would one filter errors like that?

tshu-w commented 3 years ago

@orlandini check this page? https://github.com/microsoft/pyright/blob/main/docs/configuration.md#diagnostic-rule-defaults