62 lines
1.8 KiB
Plaintext
62 lines
1.8 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Parentheses are not required after the ``++assert++``, ``++del++``, ``++elif++``, ``++except++``, ``++for++``, ``++if++``, ``++not++``, ``++raise++``, ``++return++``, ``++while++``, and ``++yield++`` keywords. Similarly, parentheses are not required after ``++in++`` in a ``++for++`` loop. Using parentheses unnecessarily impairs readability, and therefore, they should be omitted.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,python]
|
|
----
|
|
x = 1
|
|
while (x < 10):
|
|
print "x is now %d" % (x)
|
|
x += 1
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,python]
|
|
----
|
|
x = 1
|
|
while x < 10:
|
|
print "x is now %d" % (x)
|
|
x += 1
|
|
----
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove the parentheses after this "XXX" keyword
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 5 May 2017, 15:59:08 Pierre-Yves Nicolas wrote:
|
|
\[~ann.campbell.2] This rule is deprecated in favor of RSPEC-1110. However, the scope of RSPEC-1110 was reduced. Should we still deprecate this rule?
|
|
|
|
=== on 9 May 2017, 09:15:00 Freddy Mallet wrote:
|
|
Indeed [~pierre-yves.nicolas] and [~ann.campbell.2], I don't think there is any remaining overlap between this rule and RSPEC-1110.
|
|
|
|
=== on 23 Jul 2020, 11:15:39 Nicolas Harraudeau wrote:
|
|
This rule is deprecated because it raises mostly false positives on tuples and unpacking. Ex: `return (a,b)` or `for (a,b) in x:`
|
|
|
|
Also it provides very little value as there can be cases when parentheses improve readability.
|
|
|
|
|
|
Some cases deserve dedicated rules:
|
|
|
|
* S5905 "Assert should not be called on a tuple literal": it is a common bug, not a code smell.
|
|
* A rule should be created later to detect when single element tuple was intended. ex: `a = (b)` when developer probably wanted `a = (b,)`
|
|
|
|
endif::env-github,rspecator-view[]
|