
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
73 lines
1.7 KiB
Plaintext
73 lines
1.7 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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
|
|
|
|
[source,python]
|
|
----
|
|
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__
|
|
|
|
== Resources
|
|
|
|
* 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[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
* Remove this identity check; it will always be True/False
|
|
* Remove this == comparison; it will always be True/False
|
|
* Remove this != comparison; it will always be True/False
|
|
|
|
|
|
=== Highlighting
|
|
|
|
the "is", "is not", "==" or "!=" operator
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== is related to: S5914
|
|
|
|
endif::env-github,rspecator-view[]
|