Skip to content

invalid-unary-operand-type error false positive #1472

@pbaughman

Description

@pbaughman

Steps to reproduce

  1. create a file called test.py containing the following:
def frob(value=None):
    if value is not None:
        return -value
    return value
  1. pylint test.py

Current behavior

pylint output contains E: 3,15: bad operand type for unary -: NoneType (invalid-unary-operand-type)

Expected behavior

There should be no invalid-unary-operator-type error for this line because it is not possible for value to be None here

pylint --version output

pete@dev:~$ pylint --version
No config file found, using default configuration
pylint 1.7.1, 
astroid 1.5.2
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Control flowRequires control flow understandingHacktoberfestHelp wanted 🙏Outside help would be appreciated, good for new contributorsHigh effort 🏋Difficult solution or problem to solveHigh priorityIssue with more than 10 reactions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions