rspec/rules/S5727/python/rule.adoc

64 lines
1.6 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)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]