51 lines
1.4 KiB
Plaintext
51 lines
1.4 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]
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|