Skip to content

False positive for WPS504 #1036

@sobolevn

Description

@sobolevn

Bug report

What's wrong

This code produces a false positive violation:

def test():
    delta = due - since
    if not delta.days:
        raise ValidationError(FormatErrorMessages.empty_duration)
    elif delta.days > max_days:
        raise ValidationError(FormatErrorMessages.too_long_duration)
    return due

Output:

361   51:5     WPS504 Found negated condition
362   if not delta.days:
363   ^

How is that should be

We don't have an else clause here. I cannot switch this condition.
So, when else is missing, we should ignore this violation.

System information

This actually happens on 0.12.5

» flake8 --version
3.7.9 (flake8-annotations-complexity: 0.0.2, flake8-bandit: 2.1.2, flake8-broken-line: 0.1.1, flake8-bugbear: 19.8.0, flake8-comprehensions: <cached_property.cached_property object at 0x103968438>, flake8-debugger: 3.2.1, flake8-django: 0.0.3, flake8-docstrings: 1.5.0, pydocstyle: 4.0.1, flake8-eradicate: 0.2.3, flake8-executable: 2.0.3, flake8-print: 3.1.4, flake8-pytest: 1.3, flake8-string-format: 0.2.3, flake8_builtins: 1.4.1, flake8_coding: 1.3.2, flake8_commas: 2.0.0, flake8_isort: 2.3, flake8_pep3101: 1.2.1, flake8_quotes: 2.1.1, logging-format: 0.6.0, mccabe: 0.6.1, naming: 0.8.2, pycodestyle: 2.5.0, pyflakes: 2.1.1, radon: 2.4.0, rst-docstrings: 0.0.11, wemake-python-styleguide: 0.12.5) CPython 3.7.3 on Darwin

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions