rspec/rules/S1717/python/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

82 lines
2.1 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Why is this an issue?
Typically, backslashes are seen only as part of escape sequences. Therefore, the use of a backslash outside of a raw string or escape sequence looks suspiciously like a broken escape sequence.
Characters recognized as escape-able are: ``++abfnrtvox\'"++``
=== Noncompliant code example
[source,python]
----
s = "Hello \world."
t = "Nice to \ meet you"
u = "Let's have \ lunch"
----
=== Compliant solution
[source,python]
----
s = "Hello world."
t = "Nice to \\ meet you"
u = r"Let's have \ lunch" // raw string
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this "\", add another "\" to escape it, or make this a raw string.
'''
== Comments And Links
(visible only on this page)
=== on 4 Nov 2014, 15:59:00 Ann Campbell wrote:
pylint:W1401
=== on 17 Apr 2020, 15:18:27 Nicolas Harraudeau wrote:
Deprecating this rule.
It raises many issues and most of them look like False Positives. The most common false positives are strings containing regular expressions. Example:
----
import re
re.sub('\(', '[', '(test)') # False Positive
----
This rule raises 380+ issues just on Pypy.
We could try to reduce the number of false positives by focusing only on strings passed to functions which do not use backslashes, such as ``++print++`` or ``++Exception++``, but the value seems to be low. The worst that could happen is that the backslash is displayed as part of the string or that a few characters are misinterpreted:
----
In [36]: raise Exception("\.")
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-36-de3222772775> in <module>
----> 1 raise Exception("\.")
Exception: \.
In [41]: raise Exception("\234324")
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-41-d0bd825b64dd> in <module>
----> 1 raise Exception("\234324")
Exception: œ324
----
endif::env-github,rspecator-view[]