Skip to content

Negation and None #5085

@socketpair

Description

@socketpair

Bug description

Pylint incorrectly tracks types:

class Xxx:
    def __init__(self):
        self.__val = None

    @property
    def get_value(self) -> int:
        if self.__val is None:
            self.__val = 42
        return self.__val

    def method(self):
        return 'qwe'[:-self.get_value]

Configuration

No response

Command used

pylint a.py

Pylint output

a.py:12:22: E1130: bad operand type for unary -: NoneType (invalid-unary-operand-type)

Expected behavior

no errors

Pylint version

pylint 2.9.6
astroid 2.6.6
Python 3.9.7 (default, Aug 30 2021, 00:00:00) 
[GCC 11.2.1 20210728 (Red Hat 11.2.1-1)]

OS / Environment

Fedora 34

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Control flowRequires control flow understandingFalse Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions