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

functions from 'random' module incorrectly highlighted #6866

Open
ddejohn opened this issue Jan 19, 2025 · 2 comments
Open

functions from 'random' module incorrectly highlighted #6866

ddejohn opened this issue Jan 19, 2025 · 2 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@ddejohn
Copy link

ddejohn commented Jan 19, 2025

Environment data

  • Pylance version: v2024.12.1
  • OS and version: Windows 11 Education 23H2 and WSL Ubuntu
  • Python version (& distribution if applicable, e.g. Anaconda): replicated in multiple Python 3 versions

Code Snippet

# test.py
from random import choice

Settings:

// .vscode/settings.json
{
    "editor.semanticHighlighting.enabled": true
}

Repro Steps

  1. use semantic highlighting "editor.semanticHighlighting.enabled": true
  2. import any function from the random module

Expected behavior

The imported function should be highlighted as a function (typically blue), and the documentation on mouse hover should report it as a function.

Actual behavior

The imported function is un-highlighted and is reported as a variable on mouse hover.

Image

Logs

2025-01-18 22:19:11.564 [info] (Client) Pylance async client (2024.12.1) started with python extension (2024.22.2)
2025-01-18 22:19:12.027 [info] [Info  - 10:19:12 PM] (27670) Server root directory: file:///home/ddejohn/.vscode-server/extensions/ms-python.vscode-pylance-2024.12.1/dist
2025-01-18 22:19:12.034 [info] [Info  - 10:19:12 PM] (27670) Pylance language server 2024.12.1 (pyright version 1.1.389, commit ce1325fc) starting
2025-01-18 22:19:12.034 [info] [Info  - 10:19:12 PM] (27670) Starting service instance "DELETE_ME"
2025-01-18 22:19:12.125 [info] (27670) No configuration file found.
2025-01-18 22:19:12.125 [info] (27670) No pyproject.toml file found.
2025-01-18 22:19:12.126 [info] [Info  - 10:19:12 PM] (27670) Setting environmentName for service "DELETE_ME": "3.8.10 (global)"
2025-01-18 22:19:12.127 [info] [Info  - 10:19:12 PM] (27670) Setting pythonPath for service "DELETE_ME": "/bin/python3"
2025-01-18 22:19:12.127 [info] [Info  - 10:19:12 PM] (27670) No include entries specified; assuming /mnt/c/Users/devon/Documents/DELETE_ME
2025-01-18 22:19:12.128 [info] [Info  - 10:19:12 PM] (27670) Auto-excluding **/node_modules
2025-01-18 22:19:12.129 [info] [Info  - 10:19:12 PM] (27670) Auto-excluding **/__pycache__
2025-01-18 22:19:12.129 [info] [Info  - 10:19:12 PM] (27670) Auto-excluding **/.*
2025-01-18 22:19:12.162 [info] [Info  - 10:19:12 PM] (27670) Assuming Python version 3.8.10.final.0
2025-01-18 22:19:12.163 [info] (27670) Assuming Python platform Linux
2025-01-18 22:19:12.231 [info] [Info  - 10:19:12 PM] (27670) Execution environment: 3.8.10 (global)
2025-01-18 22:19:12.232 [info] [Info  - 10:19:12 PM] (27670)   Extra paths:
2025-01-18 22:19:12.232 [info] [Info  - 10:19:12 PM] (27670)     (none)
2025-01-18 22:19:12.232 [info] [Info  - 10:19:12 PM] (27670)   Python version: 3.8.10.final.0
2025-01-18 22:19:12.233 [info] [Info  - 10:19:12 PM] (27670)   Python platform: Linux
2025-01-18 22:19:12.233 [info] [Info  - 10:19:12 PM] (27670)   Search paths:
2025-01-18 22:19:12.234 [info] [Info  - 10:19:12 PM] (27670)     /home/ddejohn/.vscode-server/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stdlib
2025-01-18 22:19:12.234 [info] [Info  - 10:19:12 PM] (27670)     /mnt/c/Users/devon/Documents/DELETE_ME
2025-01-18 22:19:12.235 [info] [Info  - 10:19:12 PM] (27670)     /mnt/c/Users/devon/Documents/DELETE_ME/typings
2025-01-18 22:19:12.235 [info] [Info  - 10:19:12 PM] (27670)     /home/ddejohn/.vscode-server/extensions/ms-python.vscode-pylance-2024.12.1/dist/typeshed-fallback/stubs/...
2025-01-18 22:19:12.235 [info] [Info  - 10:19:12 PM] (27670)     /home/ddejohn/.vscode-server/extensions/ms-python.vscode-pylance-2024.12.1/dist/bundled/stubs
2025-01-18 22:19:12.236 [info] [Info  - 10:19:12 PM] (27670)     /usr/lib/python3.8
2025-01-18 22:19:12.236 [info] [Info  - 10:19:12 PM] (27670)     /usr/lib/python3.8/lib-dynload
2025-01-18 22:19:12.237 [info] [Info  - 10:19:12 PM] (27670)     /usr/local/lib/python3.8/dist-packages
2025-01-18 22:19:12.237 [info] [Info  - 10:19:12 PM] (27670)     /usr/lib/python3/dist-packages
2025-01-18 22:19:12.238 [info] [Info  - 10:19:12 PM] (27670) Adding fs watcher for library directories:
 file:///usr/lib/python3.8
file:///usr/local/lib/python3.8/dist-packages
file:///usr/lib/python3/dist-packages
2025-01-18 22:19:12.238 [info] [Info  - 10:19:12 PM] (27670) Adding fs watcher for directories:
 file:///mnt/c/Users/devon/Documents/DELETE_ME
2025-01-18 22:19:12.239 [info] (27670) Searching for source files
2025-01-18 22:19:12.243 [info] [Info  - 10:19:12 PM] (27670) Found 1 source file
2025-01-18 22:19:12.243 [info] (27670) Adding fs watcher for files:
 file:///mnt/c/Users/devon/Documents/DELETE_ME/requirements.txt
file:///mnt/c/Users/devon/Documents/DELETE_ME/pyproject.toml
2025-01-18 22:19:12.252 [info] (27670) pytest configurations: {"message":"request cancelled","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2025-01-18 22:19:12.468 [info] (27670) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2025-01-18 22:19:12.597 [info] [Info  - 10:19:12 PM] (27670) Background analysis(1) root directory: file:///home/ddejohn/.vscode-server/extensions/ms-python.vscode-pylance-2024.12.1/dist
2025-01-18 22:19:12.600 [info] [Info  - 10:19:12 PM] (27670) Background analysis(1) started
2025-01-18 22:19:12.679 [info] (27670) pytest configurations: {"message":"request cancelled","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2025-01-18 22:19:12.843 [info] (27670) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Jan 19, 2025
@erictraut
Copy link
Contributor

This is because of the way choice is defined in the community-maintained typeshed type stubs that are bundled with pylance. You can see here that choice is actually declared as a variable rather than a function. The variable is initialized with a reference to the Random.choice method.

@ddejohn
Copy link
Author

ddejohn commented Jan 19, 2025

My apologies, I meant to include screenshots of exactly that as additional context. However, I have distinct memories of the choice function being highlighted a long time ago. Am I just misremembering?

Edit: looks like I'm not misremembering 😅 -- I am still curious though why Pylance wouldn't "resolve" the bound method referenced by the variable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

3 participants