flake8-bugbear icon indicating copy to clipboard operation
flake8-bugbear copied to clipboard

False positive on B092

Open hmvp opened this issue 6 years ago • 2 comments

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

hmvp avatar Jun 06 '19 15:06 hmvp

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)

boarik avatar Jun 28 '20 09:06 boarik

Here's how pep8-naming handles it: https://github.com/PyCQA/pep8-naming#options

DylanYoung avatar Jul 03 '20 20:07 DylanYoung