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

pylance not showing using stub of current file #533

Closed
tsnowlan opened this issue Oct 28, 2020 · 4 comments
Closed

pylance not showing using stub of current file #533

tsnowlan opened this issue Oct 28, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@tsnowlan
Copy link

Environment data

  • Language Server version: Pylance language server 2020.10.2
  • OS and version: Ubuntu 20.04.1
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.9.0 / 3.7.4 via conda v4.8.4

Expected behaviour

When getting a signature preview of a function imported from another module, pylance shows the types from the associated stub if available.

When using showing the signature of a function defined in the same file, pylance should check if there is an associated stub and use that (and probably complain on mismatch if type checking is enabled).

Actual behaviour

The signature displayed while in the file does not show stub signatures. When referencing the same function in another file, the stub signature is used. The same behavior is seen whether using a stub directory or having the files side by side.

This quite unhelpful when using functions in the file they're declared in.

Logs

[Info  - 10:58:02 AM] Pylance language server 2020.10.2 (pyright d6db7c90) starting
[Info  - 10:58:02 AM] Server root directory: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist
[Info  - 10:58:02 AM] No configuration file found.
[Info  - 10:58:02 AM] Setting pythonPath for service "pylance_stub_test": "$HOME/miniconda3/envs/stub_test/bin/python"
Search paths found for configured python interpreter:
  $HOME/miniconda3/envs/stub_test/lib/python3.9/site-packages/_pdbpp_path_hack
  $HOME/lib/python
  $HOME/miniconda3/envs/stub_test/lib/python3.9
  $HOME/miniconda3/envs/stub_test/lib/python3.9/lib-dynload
  $HOME/miniconda3/envs/stub_test/lib/python3.9/site-packages
  /workspaces/stub_test
  $HOME/miniconda3/envs/stub_test/lib/python3.9/site-packages/click-7.1.2-py3.9.egg
  $HOME/miniconda3/envs/stub_test/lib/python3.9/site-packages/SQLAlchemy-1.3.20-py3.9-linux-x86_64.egg
[Info  - 10:58:04 AM] Assuming Python version 3.9
[Info  - 10:58:04 AM] Assuming Python platform Linux
[Info  - 10:58:04 AM] Searching for source files
[Info  - 10:58:04 AM] Found 4 source files
[FG] parsing: /workspaces/pylance_stub_test/bar.py (42ms)
[FG] parsing: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/2and3/builtins.pyi [fs read 4ms] (473ms)
[FG] binding: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/2and3/builtins.pyi (107ms)
[FG] binding: /workspaces/pylance_stub_test/bar.py (1ms)
[Info  - 10:58:04 AM] Background analysis(1) root directory: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist
[Info  - 10:58:04 AM] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: setFileOpened
Background analysis message: analyze
[BG(1)] analyzing: /workspaces/pylance_stub_test/bar.py ...
[BG(1)]   parsing: /workspaces/pylance_stub_test/bar.py (36ms)
[BG(1)]   parsing: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/2and3/builtins.pyi [fs read 7ms] (341ms)
[BG(1)]   binding: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/2and3/builtins.pyi (102ms)
[BG(1)]   binding: /workspaces/pylance_stub_test/bar.py (0ms)
[BG(1)]   checking: /workspaces/pylance_stub_test/bar.py ...
[BG(1)]     parsing: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/3/random.pyi [fs read 1ms] (47ms)
[BG(1)]     binding: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/3/random.pyi (2ms)
[BG(1)]     parsing: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/2and3/_typeshed/__init__.pyi [fs read 1ms] (25ms)
[BG(1)]     binding: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/2and3/_typeshed/__init__.pyi (13ms)
[BG(1)]     parsing: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/third_party/2and3/typing_extensions.pyi [fs read 1ms] (5ms)
[BG(1)]     binding: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/third_party/2and3/typing_extensions.pyi (2ms)
[BG(1)]     parsing: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/3/typing.pyi [fs read 2ms] (150ms)
[BG(1)]     binding: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/3/typing.pyi (24ms)
[BG(1)]   checking: /workspaces/pylance_stub_test/bar.py (343ms)
[BG(1)] analyzing: /workspaces/pylance_stub_test/bar.py (834ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getSemanticTokens
Background analysis message: getSemanticTokens
Background analysis message: resumeAnalysis
Background analysis message: getDiagnosticsForRange
[FG] parsing: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/3/random.pyi [fs read 2ms] (30ms)
[FG] binding: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/3/random.pyi (4ms)
[FG] parsing: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/2and3/_typeshed/__init__.pyi [fs read 1ms] (12ms)
[FG] binding: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/2and3/_typeshed/__init__.pyi (2ms)
[FG] parsing: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/third_party/2and3/typing_extensions.pyi [fs read 0ms] (4ms)
[FG] binding: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/third_party/2and3/typing_extensions.pyi (1ms)
[FG] parsing: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/3/typing.pyi [fs read 5ms] (51ms)
[FG] binding: $HOME/.vscode/extensions/ms-python.vscode-pylance-2020.10.2/dist/typeshed-fallback/stdlib/3/typing.pyi (13ms)
Background analysis message: setFileOpened
Background analysis message: getDiagnosticsForRange
[FG] parsing: /workspaces/pylance_stub_test/bar.pyi (1ms)
[FG] binding: /workspaces/pylance_stub_test/bar.pyi (1ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getSemanticTokens
[BG(1)] parsing: /workspaces/pylance_stub_test/bar.pyi (2ms)
[BG(1)] binding: /workspaces/pylance_stub_test/bar.pyi (1ms)
Background analysis message: analyze
[BG(1)] analyzing: /workspaces/pylance_stub_test/bar.pyi ...
[BG(1)]   checking: /workspaces/pylance_stub_test/bar.pyi (2ms)
[BG(1)] analyzing: /workspaces/pylance_stub_test/bar.pyi (2ms)
Background analysis message: resumeAnalysis
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: setFileOpened
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
[FG] parsing: /workspaces/pylance_stub_test/foo.py (2ms)
[FG] binding: /workspaces/pylance_stub_test/foo.py (0ms)
Background analysis message: getSemanticTokens
[BG(1)] parsing: /workspaces/pylance_stub_test/foo.py (2ms)
[BG(1)] binding: /workspaces/pylance_stub_test/foo.py (0ms)
Background analysis message: getSemanticTokens
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: analyze
[BG(1)] analyzing: /workspaces/pylance_stub_test/foo.py ...
[BG(1)]   checking: /workspaces/pylance_stub_test/foo.py (6ms)
[BG(1)] analyzing: /workspaces/pylance_stub_test/foo.py (6ms)
Background analysis message: resumeAnalysis

Code Snippet / Additional information

bar.py:

import random

def bar_gen():
    rand_bar = random.randint(1, 10)
    return bar_func(rand_bar)

def bar_func(some_int):
    return some_int * random.randint(1, 5)

bar.pyi:

def bar_func(some_int: int) -> int: ...
def bar_gen() -> int: ...

from foo.py:
in_foo

from bar.py:
in_bar

@jakebailey jakebailey added the enhancement New feature or request label Oct 28, 2020
@github-actions github-actions bot removed the triage label Oct 28, 2020
@n-peugnet
Copy link

This really is a blocker for me. I would really prefer to store the typings in stub files but without this feature I can not enable strict type checking.

@jakebailey
Copy link
Member

Ah, I didn't realize this issue was open; the main issue we've been using to track this is #1238.

@jakebailey
Copy link
Member

@n-peugnet

Can you give a little insight into why this is a blocker for you? Why would you prefer putting pyi files next to py files?

@n-peugnet
Copy link

I wanted to unobtrusively add typings to a codebase that is not mine but with which I will have to work so that I can enable strict typing to check the code while keeping it unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants