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

pyright 1.1.191 raising reportUnknownVariableType for reusable validators #3465

Closed
3 tasks done
ITProKyle opened this issue Nov 30, 2021 · 2 comments
Closed
3 tasks done
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@ITProKyle
Copy link

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.8.2
            pydantic compiled: True
                 install path: /Users/kyle/.pyenv/versions/3.9.7/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pydantic
               python version: 3.9.7 (default, Sep 22 2021, 08:26:25)  [Clang 13.0.0 (clang-1300.0.29.3)]
                     platform: macOS-11.6-x86_64-i386-64bit
     optional deps. installed: ['typing-extensions']
from typing import Any

import pydantic


def reusable_validator(v: Any) -> Any:
    return v


class MyModel(pydantic.BaseModel):
    example: str

    # Type of "_reusable_validator" is "classmethod[Unknown]" (reportUnknownVariableType)
    _reusable_validator = pydantic.validator("example", allow_reuse=True)(
        reusable_validator
    )

This appears to be caused by the latest version of typeshed changing classmethod to a generic.

Making the following change resolves this issue for the reported use case but there are other usages of classmethod that need to be updated to cover other cases that will result in the same error from pyright.

_T = TypeVar("_T", bound=AnyCallable)

def validator(
    *fields: str,
    pre: bool = False,
    each_item: bool = False,
    always: bool = False,
    check_fields: bool = True,
    whole: bool = None,
    allow_reuse: bool = False,
) -> Callable[[_T], classmethod[_T]]:
@chunleng
Copy link

@ITProKyle I used the face the same issue until I updated pydantic to 1.9. You might want to check if it solves the issue for you too

@ITProKyle
Copy link
Author

I can confirm that this was resolved in pydantic 1.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

No branches or pull requests

2 participants