50 lines
1.3 KiB
Plaintext
50 lines
1.3 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Calling the ``++not++`` or ``++~++`` prefix operator twice might be redundant: the second invocation undoes the first. Such mistakes are typically caused by accidentally double-tapping the key in question without noticing. Either this is a bug, if the operator was actually meant to be called once, or misleading if done on purpose.
|
|
Calling ``++not++`` twice is commonly done instead of using the dedicated "bool()" builtin function. However, the latter one increases the code readability and should be used.
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,python]
|
|
----
|
|
a = 0
|
|
b = False
|
|
|
|
c = not not a # Noncompliant
|
|
d = ~~b # Noncompliant
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,python]
|
|
----
|
|
a = 0
|
|
b = False
|
|
|
|
c = bool(a)
|
|
d = ~b
|
|
----
|
|
|
|
=== Exceptions
|
|
|
|
If the ``++~++`` function has been overloaded in a customised class and has been called twice, no warning is raised as it is assumed to be an expected usage.
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Use the "{not|~}" operator just once or not at all.
|
|
|
|
Use the "bool()" builtin function instead of calling "not" twice.
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|