Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive: E1130 on double unary operator #395

Open
bastian-wattro opened this issue Apr 21, 2023 · 0 comments
Open

False positive: E1130 on double unary operator #395

bastian-wattro opened this issue Apr 21, 2023 · 0 comments

Comments

@bastian-wattro
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant