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

CMD + LMB defaults to system stubs if module is overridden #6268

Closed
paulober opened this issue Aug 15, 2024 · 5 comments
Closed

CMD + LMB defaults to system stubs if module is overridden #6268

paulober opened this issue Aug 15, 2024 · 5 comments
Assignees

Comments

@paulober
Copy link

paulober commented Aug 15, 2024

Environment data

  • Pylance version: v2024.8.1
  • OS and version: macOS 15.0
  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.5

Code Snippet

json.pyi:

def dumps(obj, separators=None) -> str:
    """
    Return *obj* represented as a JSON string.

    The arguments have the same meaning as in `dump`.
    """
    ...

.vscode/settings.json

{
    "python.linting.enabled": true,
    "python.languageServer": "Pylance",
    "python.analysis.typeCheckingMode": "basic",
    "python.analysis.typeshedPaths": [
         "~/.stubs/mystubs"
    ],
    "python.analysis.extraPaths": [
        "~/.stubs/mystubs"
    ]
}

Repro Steps

  1. Create a new folder with a .vscode and settings.json.
  2. Create a typings folder with a file inside that overrides a default/included module like json. So typings/json.pyi overrides the default json. This file must contain functions that also exist in the default module but with a different function signature of optional arguments and add a doc-string to the function declaration that differs from the normal one. (you can find an example above)
  3. Now create a main.py an include you custom module (like import json).
  4. Type module_name. and wait for auto suggestions.
  5. Press enter and call the function with the correct parameters.
  6. CMD / STRG + Left mous button on the function name

Expected behavior

  • The extension shows your doc-string and functions
  • The extension opens the correct override_module.pyi you created.

Actual behavior

  • It shows you doc-string and functions and uses them for syntax high-lighting of errors if you try to use an optional parameter that only exists on the system module definition.
  • But if you left click on the function it takes you to the original system module definition instead of your custom implementation which doc-string and function signature is also displayed.

Logs

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

rchiodo commented Aug 15, 2024

Thanks for the issue but this is by design. CMD+Left Click goes to the definition of the function, not the declaration. Stubs are declarations.

The difference is more pronounced on the context menu:

Image

@rchiodo rchiodo added by design and removed needs repro Issue has not been reproduced yet labels Aug 15, 2024
@rchiodo rchiodo closed this as completed Aug 15, 2024
@paulober
Copy link
Author

Thanks for the issue but this is by design. CMD+Left Click goes to the definition of the function, not the declaration. Stubs are declarations.

Thanks for the explanation. Is it possible per setting to enable go to declaration for CMD + LMB?

@rchiodo
Copy link
Contributor

rchiodo commented Aug 16, 2024

Is it possible per setting to enable go to declaration for CMD + LMB?

I don't believe mouse clicks are rewriteable, but you could make a keyboard shortcut for it. Or rewrite F12 to goto declaration instead.

Right now F12 is goto definition:

Image

@paulober
Copy link
Author

Ok, thanks.

@debonte
Copy link
Contributor

debonte commented Aug 16, 2024

I don't believe mouse clicks are rewriteable,

@paulober, you could up-vote this issue: microsoft/vscode#3130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants