rspec/rules/S2319/python/rule.adoc
2023-07-04 10:41:26 +02:00

40 lines
939 B
Plaintext

This rule raises an issue when a pre/post increment or decrement operator is used.
== Why is this an issue?
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++``.
=== Code examples
==== Noncompliant code example
[source,python,diff-id=1,diff-type=noncompliant]
----
++x # Noncompliant: pre and post increment operators do not exist in Python.
x-- # Noncompliant: pre and post decrement operators do not exist in Python.
----
==== Compliant solution
[source,python,diff-id=1,diff-type=compliant]
----
x += 1
x -= 1
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Python does not include the [pre|post][increment|decrement] operator.
endif::env-github,rspecator-view[]