Validator's first agument warning when using @pydantic.validator
See original GitHub issueDescribe 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:
- Define a pydantic model
- Define avalidator function using
@pydantic.validator(...)
as a decorator instead of using@validator(...)
- See error
Expected behavior
PyCharm should not warn about using self
instead cls
since validator()
returns class method
Screenshots
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
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Validators - pydantic
validators are "class methods", so the first argument value they receive is the UserModel class, not an instance of UserModel . the second...
Read more >How to Validate Your Data with Custom Validators of Pydantic ...
Since a validator works as a class method, the first argument is the class which is named cls as a convention.
Read more >pylint complain on models with validators since version 0.27
model.py:12:4: E0213: Method should have "self" as first argument (no-self-argument) ... These complaints does not occur with pydantic 0.26.
Read more >How we validate input data using pydantic
Pydantic raises a ValidationError when the validation of the model fails, stating which field, i.e. attribute, raised the error and why. In this ......
Read more >Strict Type Validation With Pydantic - Section.io
Type validation is the process of making sure what you get is what you are expecting. If an endpoint is supposed to get...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 Hello, I just tried to reproduce and found that the import statement was
import pydantic.generics
instead ofimport pydantic
. I think because the other place in the same file was usingpydantic.generics.Generic
.I also found that it isn’t practical to import like that and using
pydantic.validator
later. Changing the import statement back toimport pydantic
works. I’m not sure if there is anything to fix in this case. Thanks!