-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
invalid-unary-operand-type error false positive #1472
Comments
Just bumped into this with import numpy
def foobar(value=None):
a = numpy.array([1, 2, 3])
return +a, -a |
Same issue, e.x. import numpy as np
def position_camera(dq=(0, 0, 0, 0), dT=(0, 0, 0)):
q = -np.array((0.0, 1.0, 0.15, 0.35)) + dq
# ... |
When using @pbaughman's snipped from the issue description for testing, it seems the false positive appeared with Pylint release Using the older release |
I have a similar issue with the following code:
Pylint output: |
Folks, not all these examples are the same problem. :) I would suggest for some of them to be in their separate issues, since we don't need flow control for correctly checking numpy arrays or |
After two years this looks like still an issue. Any ideas on how to solve this? |
@nschloe @JVillella the bug you were facing with I let this issue open because initial report was dealing with Please do not add any reports here unless it is directly related to |
Not sure if this qualifies as # func.py
def func(moo = None):
return -moo if moo else 0 $ pylint func
************* Module func
func.py:2: [E1130(invalid-unary-operand-type), func] bad operand type for unary -: NoneType
----------------------------------------------------------------------
Your code has been rated at -15.00/10 (previous run: -15.00/10, +0.00)
$ pylint --version
pylint 2.7.2
astroid 2.5.1
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] |
Using if value_sign == "-":
# pylint: disable=invalid-unary-operand-type
raw_value = (-raw_value)
# pylint: enable=invalid-unary-operand-type
raw_value = (-raw_value) # this line will be also suppressed. |
Steps to reproduce
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
The text was updated successfully, but these errors were encountered: