flake8-bugbear
flake8-bugbear copied to clipboard
False positive on B092
Pydantic validator decorators make classmethods from the decorated methods but these are flagged as instance methods
The following gets flagged:
class UserModel(BaseModel):
name: str
@validator('name')
def name_must_contain_space(cls, v):
if ' ' not in v:
raise ValueError('must contain a space')
return v.title()
changing cls to self gives no error
I believe this is B902. I'm experiencing the same issue. (related issue in a pylint+pydantic context https://github.com/samuelcolvin/pydantic/issues/568)
Here's how pep8-naming handles it: https://github.com/PyCQA/pep8-naming#options