2023-07-04 10:41:26 +02:00
This rule raises an issue when a pre/post increment or decrement operator is used.
2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 16:49:39 +02:00
Python has no pre/post increment/decrement operator. For instance, ``x{plus}{plus}`` and ``++x--++`` will fail to parse. More importantly, ``{plus}{plus}x`` and ``++--x++`` will do nothing. To increment a number, simply write ``++x += 1++``.
2023-07-04 10:41:26 +02:00
=== Code examples
2021-04-28 18:08:03 +02:00
2023-07-04 10:41:26 +02:00
==== Noncompliant code example
2021-04-28 16:49:39 +02:00
2023-07-04 10:41:26 +02:00
[source,python,diff-id=1,diff-type=noncompliant]
2021-04-28 16:49:39 +02:00
----
2023-07-04 10:41:26 +02:00
++x # Noncompliant: pre and post increment operators do not exist in Python.
x-- # Noncompliant: pre and post decrement operators do not exist in Python.
2021-04-28 16:49:39 +02:00
----
2021-04-28 18:08:03 +02:00
2023-07-04 10:41:26 +02:00
==== Compliant solution
2021-04-28 16:49:39 +02:00
2023-07-04 10:41:26 +02:00
[source,python,diff-id=1,diff-type=compliant]
2021-04-28 16:49:39 +02:00
----
x += 1
2023-07-04 10:41:26 +02:00
x -= 1
2021-04-28 16:49:39 +02:00
----
2021-04-28 18:08:03 +02:00
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Python does not include the [pre|post][increment|decrement] operator.
2021-09-20 15:38:42 +02:00
endif::env-github,rspecator-view[]