rspec/rules/S5727/python/rule.adoc
2021-04-28 18:08:03 +02:00

44 lines
1.2 KiB
Plaintext

Checking if a variable or parameter is ``++None++`` should only be done when you expect that it can be ``++None++``. Doing so when the variable is always None or never None is confusing at best. At worse, there is a bug and the variable is not updated properly.
This rule raises an issue when expressions ``++X is None++``, ``++X is not None++``, ``++X == None++`` or ``++X != None++`` are constant, i.e. ``++X++`` is always None or never None.
== Noncompliant Code Example
----
mynone = None
result = mynone is None: # Noncompliant. Always True.
if mynone == None: # Noncompliant. Always True.
pass
if mynone is not None: # Noncompliant. Always False.
pass
if mynone == None: # Noncompliant. Always False.
pass
myint = 42
result = myint is None: # Noncompliant. Always False.
if myint == None: # Noncompliant. Always False.
pass
if myint is not None: # Noncompliant. Always True.
pass
if myint == None: # Noncompliant. Always True.
pass
----
:link-with-uscores1: https://docs.python.org/3/reference/datamodel.html#object.__eq__
== See
* Python documentation - https://docs.python.org/3/reference/expressions.html#is-not[Identity comparisons]
* Python documentation - {link-with-uscores1}[``++__eq__++`` operator]