You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
N804 First argument of a class method should be named `cls`
|
19 | @pydantic.model_validator(mode="after")
20 | def after_validation(self):
| ^^^^ N804
21 | """After Validation."""
22 | if not self.bar:
|
= help: Rename `self` to `cls`
Which is slightly... annoying. We know we can remove this from config and add a class method decorator, but this has always felt a bit verbose to use.
Is there a better way to handle this case? is this something ruff would consider fixing?
The text was updated successfully, but these errors were encountered:
@field_validators are "class methods", so the first argument value they receive is the UserModel class, not an instance of UserModel. We recommend you use the @classmethod decorator on them below the @field_validator decorator to get proper type checking.
We have the following in our ruff config:
This is so we can do the following in our code:
This works well, however when we set the validator mode to "after", this is an instance method rather than a class method, so we get:
We get the following:
Which is slightly... annoying. We know we can remove this from config and add a class method decorator, but this has always felt a bit verbose to use.
Is there a better way to handle this case? is this something ruff would consider fixing?
The text was updated successfully, but these errors were encountered: