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

*args positional parameter dropped out and became a phantom when using Concatenate to shorten parameters #9630

Open
NCBM opened this issue Dec 25, 2024 · 2 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@NCBM
Copy link

NCBM commented Dec 25, 2024

Describe the bug

When using typing.Concatenate to reduce parameters (just like a part of partial function), I found the positional parameter *args (or any other name) dropped out of the parameter list after a Concatenate operation and become a phantom in pyright, which is not printed in parameter type while type checking of the *args still works.

I also tested the code in pylance but the error is even not reported.

Code or Screenshots

from typing import Callable, Concatenate, reveal_type


def _onepartial[T, **P, R](fn: Callable[Concatenate[T, P], R], val: T) -> Callable[P, R]:
    ...


def test2(p1: int, *ps: str) -> None:
    ...


reveal_type(_onepartial(test2, 3))
reveal_type(_onepartial(_onepartial(test2, 3), "foo"))  # *ps dropped out
reveal_type(
    _onepartial(
        _onepartial(
            _onepartial(test2, 3),
            "foo"
        ),
        "bar"  # no error since *ps type match, although which becomes a phantom
    )
)
reveal_type(
    _onepartial(
        _onepartial(
            _onepartial(test2, 3),
            "foo"
        ),
        3  # error since *ps type mismatch, although which becomes a phantom
    )
)

View in pyright-play.net

VS Code extension or command-line

Tested in:

  • pyright-play.net: pyright 1.1.391, python 3.13;
  • vscode: pylance 2024.12.1, python 3.13, however not reporting the error as commented.
@NCBM NCBM added the bug Something isn't working label Dec 25, 2024
erictraut added a commit that referenced this issue Dec 25, 2024
…e with a "*args" parameter to a callable with a `Concatenate` and `ParamSpec`. This addresses #9630.
erictraut added a commit that referenced this issue Dec 25, 2024
…e with a "*args" parameter to a callable with a `Concatenate` and `ParamSpec`. This addresses #9630. (#9632)
@erictraut
Copy link
Collaborator

Thanks for the issue. The typing spec isn't entirely clear how a Concatenate should be used in conjunction with a *args parameter, but I agree that your interpretation (which is consistent with mypy's interpretation) makes sense. I'll change pyright's behavior to match. This will be included in the next release.

Pylance doesn't show this error because it defaults typeCheckingMode to "off". If you set this to "standard", you'll see the same errors reported by pyright.

@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Dec 25, 2024
@NCBM
Copy link
Author

NCBM commented Dec 26, 2024

thanks. maybe I forgot to change the typeCheckingMode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants