pylint-django icon indicating copy to clipboard operation
pylint-django copied to clipboard

False positive: E1130 on double unary operator

Open bastian-wattro opened this issue 2 years ago • 0 comments

Bug description

Since 2.17.2 Pylint does not accept using a double negation on django Q objects. I reproduced the issue in a venv using Python 3.10.10 with nothing but pylint and django installed. The issue also occures when only using pylint. I reported this issue to pylint, but was asked to report it here.

"""Bug reproduction: false positive E1130"""
from django.db.models import Q

def false_positive(need_text=False) -> Q:
    """note the double negation"""
    has_text = ~Q(text="")
    if need_text:
        return has_text
    return ~has_text # E1130: bad operand type for unary ~: Node (invalid-unary-operand-type)

def this_is_ok(need_text=False) -> Q:
    """no double negation here"""
    has_no_text = Q(text="")
    if need_text:
        return ~has_no_text
    return has_no_text

Configuration

no_settings.py is an empty file

$ pip freeze
asgiref==3.6.0
astroid==2.15.3
dill==0.3.6
Django==4.2
isort==5.12.0
lazy-object-proxy==1.9.0
mccabe==0.7.0
platformdirs==3.2.0
pylint==2.17.2
pylint-django==2.5.3
pylint-plugin-utils==0.7
sqlparse==0.4.4
tomli==2.0.1
tomlkit==0.11.7
typing_extensions==4.5.0
wrapt==1.15.0

Command used

DJANGO_SETTINGS_MODULE='no_settings' pylint --load-plugins pylint_django reproduce.py

Pylint output

************* Module reproduce
reproduce.py:9:11: E1130: bad operand type for unary ~: Node (invalid-unary-operand-type)

Expected behavior

Same behaviour as in v2.17.1 (no error)

bastian-wattro avatar Apr 21 '23 12:04 bastian-wattro