43 lines
989 B
Plaintext
43 lines
989 B
Plaintext
== Why is this an issue?
|
|
|
|
The repetition of a prefix operator (``++not++`` or ``++~++``) is usually a typo. The second operator invalidates the first one:
|
|
|
|
[source,python]
|
|
----
|
|
a = False
|
|
b = ~~a # Noncompliant: equivalent to "a"
|
|
----
|
|
|
|
While calling ``++not++`` twice is equivalent to calling the `bool()` built-in function, the latter increases the code readability, so it should be preferred.
|
|
|
|
[source,python]
|
|
----
|
|
a = 0
|
|
|
|
b = not not a # Noncompliant: use bool()
|
|
----
|
|
|
|
=== Exceptions
|
|
|
|
The rule does not raise an issue if the ``++~++`` function is overloaded in a customized class, as it is assumed to be the 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[]
|