2023-05-03 11:06:20 +02:00
== Why is this an issue?
2023-06-22 17:24:32 +02:00
The repetition of a prefix operator (``++not++`` or ``++~++``) is usually a typo. The second operator invalidates the first one:
2022-03-14 15:07:47 +01:00
[source,python]
----
2023-06-16 16:00:06 +02:00
a = False
b = ~~a # Noncompliant: equivalent to "a"
2022-03-14 15:07:47 +01:00
----
2023-06-16 16:00:06 +02:00
While calling ``++not++`` twice is equivalent to calling the `bool()` built-in function, the latter increases the code readability, so it should be preferred.
2022-03-14 15:07:47 +01:00
[source,python]
----
a = 0
2023-06-16 16:00:06 +02:00
b = not not a # Noncompliant: use bool()
2022-03-14 15:07:47 +01:00
----
2021-06-02 20:44:38 +02:00
2023-05-03 11:06:20 +02:00
=== Exceptions
2022-03-18 17:41:25 +01:00
2023-06-16 16:00:06 +02:00
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.
2022-03-18 17:41:25 +01:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
2022-03-14 15:07:47 +01:00
=== Message
Use the "{not|~}" operator just once or not at all.
2021-09-20 15:38:42 +02:00
2022-03-18 17:41:25 +01:00
Use the "bool()" builtin function instead of calling "not" twice.
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
2023-06-22 10:38:01 +02:00
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]