Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyright/Pylance inconsistency: Unknown import symbol sklearn #6410

Closed
einarwar opened this issue Sep 18, 2024 · 6 comments
Closed

Pyright/Pylance inconsistency: Unknown import symbol sklearn #6410

einarwar opened this issue Sep 18, 2024 · 6 comments
Assignees
Labels
bug Something isn't working fixed in next version (release) A fix has been implemented and will appear in an upcoming version typestub Issue relating to our bundled type stubs

Comments

@einarwar
Copy link

Environment data

  • Language Server version: 2024.9.1
  • OS and version: linux x64
  • Python version (and distribution if applicable, e.g. Anaconda): 3.12.6
  • python.analysis.indexing: true
  • python.analysis.typeCheckingMode: basic
  • scikit-learn version: 1.5.2
  • pyright version: 1.1.380
  • Runs in a devcontainer

I have been having an annoyance for some time, where pylance and pyright behaves inconsistently.

from sklearn.metrics import root_mean_squared_error

Pyright does not flag this as an issue, while pylance gives the error:

"root_mean_squared_error" is unknown import symbolPylance[reportAttributeAccessIssue](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportAttributeAccessIssue)

When i select sklearn.metrics -> go to definition using the python environment where sklearn is installed, i get to site-packages/sklearn/metrics/__init__.py where root_mean_squared_error correctly is.

If i however select a python interpreter without sklearn installed, when i go to the definition, i am directed to home/vscode/.vscode-server/extensions/ms-python.vscode-pylance-2024.9.1/dist/bundled/stubs/sklearn/metrics/__init__.pyi, where the function root_mean_squared_error does not exist.

Expected behavior

Would expect pylance to behave as pyright in this case, i.e give no error

Actual behavior

Pylance raises an error, while pyright doesn't

Logs

When checking the output from Python Language Server, there are two entries that might be related:

2024-09-18 19:22:34.475 [info] [Info  - 7:22:34 PM] (31165) [BG(1)] Long operation: checking: file:///usr/local/lib/python3.12/site-packages/sklearn/metrics/__init__.py (4947ms)
2024-09-18 19:22:34.481 [info] [Info  - 7:22:34 PM] (31165) [BG(1)] Long operation: analyzing: file:///usr/local/lib/python3.12/site-packages/sklearn/metrics/__init__.py (4956ms)

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Sep 18, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Sep 18, 2024

Thanks for the issue. This is because our bundled type stubs don't match your scikit-learn version. The stubs here need to be updated:
https://github.com/microsoft/python-type-stubs/tree/main/stubs/sklearn

@rchiodo rchiodo added typestub Issue relating to our bundled type stubs bug Something isn't working and removed needs repro Issue has not been reproduced yet labels Sep 18, 2024
@einarwar
Copy link
Author

Thanks for the quick response. Should i raise an issue in that repo as well?

@rchiodo
Copy link
Contributor

rchiodo commented Sep 18, 2024

Yeah it wouldn't hurt. Somebody might have the time to update those stubs.

@einarwar
Copy link
Author

Took the matter into my own hands: microsoft/python-type-stubs#317

One question though: Is this expected behaviour by pylance? I have read about the differences between pylance and pyright, e.g useLibraryCodeForTypes. I tried with this setting both enabled and disabled, without any effect. I would have thought that the default behaviour regardless would be to inspect the package if it was installed. However, scikit-learn does not have a py.typed file, which might have an effect here

@debonte
Copy link
Contributor

debonte commented Sep 19, 2024

Took the matter into my own hands: microsoft/python-type-stubs#317

Thanks @einarwar! I just merged your PR. It will show up in next week's prerelease build.

useLibraryCodeForTypes. I tried with this setting both enabled and disabled, without any effect.

useLibraryCodeForType only comes into play when no stubs are found. You can read more about our resolution order here.

@debonte debonte added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Sep 19, 2024
@bschnurr bschnurr added fixed in next version (release) A fix has been implemented and will appear in an upcoming version and removed fixed in next version (main) A fix has been implemented and will appear in an upcoming version labels Sep 26, 2024
@StellaHuang95
Copy link
Contributor

This issue has been fixed in prerelease version 2024.9.102, which we've just released. You can find the changelog here: CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (release) A fix has been implemented and will appear in an upcoming version typestub Issue relating to our bundled type stubs
Projects
None yet
Development

No branches or pull requests

5 participants