pydantic-pycharm-plugin icon indicating copy to clipboard operation
pydantic-pycharm-plugin copied to clipboard

Validator's first agument warning when using @pydantic.validator

Open earthpyy opened this issue 3 years ago • 6 comments

Describe the bug PyCharm is not seeing validator function as a class method when using @pydantic.validator instead of @validator

To Reproduce Steps to reproduce the behavior:

  1. Define a pydantic model
  2. Define avalidator function using @pydantic.validator(...) as a decorator instead of using @validator(...)
  3. See error

Expected behavior PyCharm should not warn about using self instead cls since validator() returns class method

Screenshots image

image

Environments (please complete the following information):

  • IDE: PyCharm Professional 2021.1
  • OS: macOS Big Sur
  • Pydantic Version: 1.8.2
  • Plugin version: 0.3.4

Additional context None

earthpyy avatar Jul 14 '21 10:07 earthpyy

@earthpyy Thank you for reporting this issue. I don't expect the parrtern. I will fix it.

koxudaxi avatar Jul 15 '21 16:07 koxudaxi

@earthpyy Thank you for reporting this issue. I don't expect the parrtern. I will fix it.

@koxudaxi Thanks very much! Also thanks for this great work as well!

earthpyy avatar Jul 19 '21 03:07 earthpyy

@earthpyy I'm sorry for my late reply. I can't reproduce your warning.

Would you please give me the code? Screenshot from 2021-08-04 02-43-27

koxudaxi avatar Aug 03 '21 17:08 koxudaxi

@koxudaxi Hello, I just tried to reproduce and found that the import statement was import pydantic.generics instead of import pydantic. I think because the other place in the same file was using pydantic.generics.Generic.

I also found that it isn't practical to import like that and using pydantic.validator later. Changing the import statement back to import pydantic works. I'm not sure if there is anything to fix in this case. Thanks!

earthpyy avatar Aug 05 '21 17:08 earthpyy

That's good news. I'm happy to resolve your problem.

I don't close this issue now. If I get the time then I will check the problem deeply.

koxudaxi avatar Aug 08 '21 08:08 koxudaxi

Thanks for your help!

earthpyy avatar Aug 09 '21 03:08 earthpyy