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

New Position-only parameter mismatch with 1.1.344 #6876

Closed
sherbang opened this issue Jan 2, 2024 · 1 comment
Closed

New Position-only parameter mismatch with 1.1.344 #6876

sherbang opened this issue Jan 2, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@sherbang
Copy link

sherbang commented Jan 2, 2024

Describe the bug
After upgrading from 1.1.343 to 1.1.344 I can no longer find a way to annotate my pydantic validators that pyright will accept.

I was able to replicate the problem with the below reduced code sample.

(Note: I also had to rename my value parameter to __value to match the Protocol, but that seems like an unnecessary requirement since these are position-only parameters)

Code or Screenshots

from collections.abc import Callable
from typing import Any, Protocol


class ModelBeforeValidatorWithoutInfo(Protocol):
    def __call__(
        self,
        cls: Any,
        __value: Any,
    ) -> Any:
        ...


def model_validator() -> Callable[[ModelBeforeValidatorWithoutInfo], Any]:
    ...


class FakeModel:
    @model_validator()
    @classmethod
    def test(cls, __value: Any) -> Any:
        ...

    @model_validator()
    @classmethod
    def test1(cls, __value: Any, /) -> Any:
        ...

Output:

/path/to/pyright_bug.py
  /path/to/pyright_bug.py:19:6 - error: Argument of type "(cls: type[Self@FakeModel], __value: Any, /) -> Any" cannot be assigned to parameter of type "ModelBeforeValidatorWithoutInfo"
    Type "(cls: type[Self@FakeModel], __value: Any, /) -> Any" cannot be assigned to type "(cls: Any, __value: Any) -> Any"
      Position-only parameter mismatch; parameter "cls" is not position-only
      Position-only parameter mismatch; parameter "__value" is not position-only
      Position-only parameter mismatch; expected 2 but received 0 (reportGeneralTypeIssues)
  /path/to/pyright_bug.py:24:6 - error: Argument of type "(cls: type[Self@FakeModel], __value: Any, /) -> Any" cannot be assigned to parameter of type "ModelBeforeValidatorWithoutInfo"
    Type "(cls: type[Self@FakeModel], __value: Any, /) -> Any" cannot be assigned to type "(cls: Any, __value: Any) -> Any"
      Position-only parameter mismatch; parameter "cls" is not position-only
      Position-only parameter mismatch; parameter "__value" is not position-only
      Position-only parameter mismatch; expected 2 but received 0 (reportGeneralTypeIssues)
2 errors, 0 warnings, 0 informations 

If your code relies on symbols that are imported from a third-party library, include the associated import statements and specify which versions of those libraries you have installed.

VS Code extension or command-line
Are you running pyright as a VS Code extension, a language server in another editor, integrated into Pylance, or the command-line tool? Which version?

Running the command-line using the python wrapper:

> pyright --version
pyright 1.1.344
@sherbang sherbang added the bug Something isn't working label Jan 2, 2024
@erictraut
Copy link
Collaborator

This is a duplicate of #6875. Looks like both bugs were filed within a couple of minutes of each other :). I'm going to close this one in favor of the other one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants