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

Callable with two parameters, called with a starred pair, "Expected 1 more positional argument" #2083

Closed
ajkaijanaho opened this issue Nov 17, 2021 · 3 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@ajkaijanaho
Copy link

Environment data

  • Language Server version: 2021.11.1
  • OS and version: win32 x64
  • Python version (and distribution if applicable, e.g. Anaconda): Python 3.9.6, Python 3.10.0 (python.org)
  • python.analysis.indexing: undefined
  • python.analysis.typeCheckingMode: basic

Expected behaviour

In the code snippets below, the call to g is well typed.

Actual behaviour

In the code snippets below, the call to g is diagnosed as "Expected 1 more positional argument".

Logs

Python Language Server Log (analyzing the first snippet below)

[Info  - 15.53.48] Pylance language server 2021.11.1 (pyright 446a9bdb) starting
[Info  - 15.53.48] Server root directory: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist
[Info  - 15.53.48] No pyproject.toml file found.
[Info  - 15.53.48] Setting pythonPath for service "<default>": "C:\Program Files\Python310\python.exe"
[Warn  - 15.53.48] stubPath typings is not a valid directory.
[Info  - 15.53.48] Assuming Python version 3.10
[Info  - 15.53.48] Assuming Python platform Windows
Search paths for <default>
  c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib
  typings
  c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stubs\...
  c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\bundled\stubs
  c:\Program Files\Python310\DLLs
  c:\Program Files\Python310\Lib
  c:\Program Files\Python310
  c:\Program Files\Python310\Lib\site-packages
[Info  - 15.53.48] Searching for source files
[Info  - 15.53.48] No source files found.
[Info  - 15.53.48] Background analysis(1) root directory: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist
[Info  - 15.53.48] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: setImportResolver
Background analysis message: ensurePartialStubPackages
[FG] parsing: c:\Users\akaijanaho\foo.py (17ms)
[FG] parsing: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 3ms] (86ms)
[FG] binding: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\builtins.pyi (32ms)
[FG] binding: c:\Users\akaijanaho\foo.py (0ms)
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: setFileOpened
Background analysis message: getSemanticTokens full
[BG(1)] getSemanticTokens full at c:\Users\akaijanaho\foo.py ...
[BG(1)]   parsing: c:\Users\akaijanaho\foo.py (20ms)
[BG(1)]   parsing: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\builtins.pyi [fs read 3ms] (83ms)
[BG(1)]   binding: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\builtins.pyi (33ms)
[BG(1)]   binding: c:\Users\akaijanaho\foo.py (0ms)
[BG(1)]   parsing: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\typing.pyi [fs read 2ms] (31ms)
[BG(1)]   binding: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\typing.pyi (10ms)
[BG(1)]   parsing: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi [fs read 0ms] (11ms)
[BG(1)]   binding: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\_typeshed\__init__.pyi (2ms)
[BG(1)]   parsing: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\types.pyi [fs read 0ms] (13ms)
[BG(1)]   binding: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\types.pyi (4ms)
[BG(1)]   parsing: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi [fs read 1ms] (4ms)
[BG(1)]   binding: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\typing_extensions.pyi (2ms)
[BG(1)]   parsing: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\abc.pyi [fs read 0ms] (1ms)
[BG(1)]   binding: c:\Users\akaijanaho\.vscode\extensions\ms-python.vscode-pylance-2021.11.1\dist\typeshed-fallback\stdlib\abc.pyi (0ms)
[BG(1)] getSemanticTokens full at c:\Users\akaijanaho\foo.py (256ms)
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 0:0 - 8:0 at c:\Users\akaijanaho\foo.py (1ms)
Background analysis message: analyze
[BG(1)] analyzing: c:\Users\akaijanaho\foo.py ...
[BG(1)]   checking: c:\Users\akaijanaho\foo.py (7ms)
[BG(1)] analyzing: c:\Users\akaijanaho\foo.py (7ms)
Background analysis message: resumeAnalysis

Code Snippet / Additional information

from typing import Callable, Tuple


def f(g: Callable[[int, str], None], v: Tuple[int, str]) -> None:
    g(*v)

f((lambda x, y: print(x,y)), (2,"hi"))

In fact, even simpler:

from typing import Callable

g: Callable[[int, str], None] = lambda x, y: print(x,y)

g(*(2,"hi"))

Both programs run fine.

Note that in both examples, the tuple is statically declared to have the correct number and type of elements to function as g's starred argument.

The actual case where this arises is, of course, much more complex (and a part of a proprietary code base).

@erictraut
Copy link
Contributor

Thanks for filing the issue. I'm able to repro the problem, and I agree it's a bug. The unpack operator is properly handled in the case where positional-only parameters are not used (such as in your lambda example), but it is incorrectly applied when positional-only parameters are used, as in the case of a Callable type. The same problem occurs when a positional-only separator is explicitly used in a function signature, like this:

def f(a: int, b: str, /):
    ...

I've created a tracking bug in the pyright repo, since this bug is within the core type checking logic.

@judej judej added the needs investigation Could be an issue - needs investigation label Nov 17, 2021
@github-actions github-actions bot removed the triage label Nov 17, 2021
@judej judej added bug Something isn't working triage and removed needs investigation Could be an issue - needs investigation triage labels Nov 17, 2021
@erictraut
Copy link
Contributor

This will be fixed in the next release.

@erictraut erictraut added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Nov 18, 2021
@bschnurr
Copy link
Member

bschnurr commented Dec 2, 2021

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

@bschnurr bschnurr closed this as completed Dec 2, 2021
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 (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

4 participants