microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 769 forks source link

Argument missing for parameter - but I'm using a different override #951

Closed cpwood closed 3 years ago

cpwood commented 3 years ago

I've got a .pyi file containing this (take note of the constructors for range):

image

but Pylance is telling me this:

image

It seems like it's picking up the second of the two __init__ methods only when both should be available.

I'm sure this is probably something I'm doing wrong somewhere, but I can't tell what! Would appreciate any pointers!

My settings.json file is as follows:

{
    "python.linting.enabled": true,
    "python.autoComplete.extraPaths": [
        ".vscode/Pico-Stub/frozen",
        ".vscode/Pico-Stub/stubs"
    ],
    "python.autoComplete.typeshedPaths": [
        ".vscode/Pico-Stub/frozen",
        ".vscode/Pico-Stub/stubs"
    ],
    "python.analysis.typeshedPaths": [
        ".vscode/Pico-Stub/frozen",
        ".vscode/Pico-Stub/stubs"
    ],
    "python.linting.pylintEnabled": false,
    "python.languageServer": "Pylance",
    "python.linting.ignorePatterns": [
        ".vscode/*.py",
        "**/*_asm.py"
    ],
    "python.analysis.extraPaths": [
        ".vscode/Pico-Stub/frozen",
        ".vscode/Pico-Stub/stubs"
    ],
    "python.analysis.typeCheckingMode": "basic"
}

Pylance 2021.2.2

erictraut commented 3 years ago

If you right-click on range in your ".py" file and choose "Go to Declaration", where does it take you? I'm guessing that it won't take you to your ".pyi" file and instead will take you to the typeshed file builtins.pyi that is bundled with pylance.

One problem that I see immediately is that Pylance supports only one typeshed path override using the python.analysis.typeshedPaths setting, but you're providing two paths. The second path here will be ignored. The feature is designed to allow you to download newer or older versions of typeshed stdlib stubs and use those rather than the bundled version. It is not meant to allow for multiple typeshed search paths.

If your intent is to specify stubs other than stdlib typeshed stubs, you should use the python.anslysis.stubPath setting and place all stub packages in their own subdirectories within that path.

cpwood commented 3 years ago

Many thanks, @erictraut!

Choosing "Go to Declaration" does take me to my .pyi file rather than the typeshed one. So it's picking up the right file.

I'm also seeing other overload-related issues. This is from another .pyi file altogether:

image

It's for a module that's baked into MicroPython so I can't change anything about the names / signatures and I was anticipating that the @overloads attribute would mean that this particular error wouldn't appear (I think this might be new feature in the current version).

For context, my use-case is that I'm trying to put together some stubs for use with MicroPython and the Raspberry Pi Pico. As you may know, there's a reduced surface area in MicroPython compared to standard Python and what you'd see in typeshed, and a few other differences too.

Noted on the typshedPaths setting. As it happens, I'm wanting it to target the "frozen" folder for the moment so it's not a problem, but I acknowledge that it needs changing up a bit. It's still half way between Pylint and Pylance worlds at the moment, config-wise, too.

erictraut commented 3 years ago

I suspect that it's not recognizing the @overload decorator. This is a special symbol that has special meaning to a type checker.

Can you show me how you've defined overload in your typeshed stubs — and where you've exported it? Pyright assumes that it's defined in typing.pyi or typing_extensions.pyi, and it should look like the following:

overload = object()
cpwood commented 3 years ago

Just wanted to thank you, @erictraut - that was exactly the problem. overload wasn't exported properly. All working fine now!