contrib: enforce wrapping too-long lines with () instead of \
authorAugie Fackler <augie@google.com>
Sun, 13 Jan 2019 20:27:00 -0500
changeset 41761 e2472b12c842
parent 41760 1eb2fc21da12
child 41762 cde37ed080c9
contrib: enforce wrapping too-long lines with () instead of \ This is the style I prefer, and an anecdotal exploration of styles recommended in style guides etc. Further, to quote pep8: > The preferred way of wrapping long lines is by using Python's implied > line continuation inside parentheses, brackets and braces. Long lines > can be broken over multiple lines by wrapping expressions in > parentheses. These should be used in preference to using a backslash > for line continuation. So I think this is a virtuous change. Differential Revision: https://phab.mercurial-scm.org/D5995
contrib/check-code.py
tests/test-contrib-check-code.t
--- a/contrib/check-code.py	Wed Feb 20 18:02:28 2019 -0500
+++ b/contrib/check-code.py	Sun Jan 13 20:27:00 2019 -0500
@@ -233,6 +233,7 @@
 
 pypats = [
   [
+    (r'\\$', 'Use () to wrap long lines in Python, not \\'),
     (r'^\s*def\s*\w+\s*\(.*,\s*\(',
      "tuple parameter unpacking not available in Python 3+"),
     (r'lambda\s*\(.*,.*\)',
--- a/tests/test-contrib-check-code.t	Wed Feb 20 18:02:28 2019 -0500
+++ b/tests/test-contrib-check-code.t	Sun Jan 13 20:27:00 2019 -0500
@@ -7,6 +7,9 @@
   > def toto( arg1, arg2):
   >     del(arg2)
   >     return ( 5+6, 9)
+  > def badwrap():
+  >     return 1 + \\
+  >        2
   > NO_CHECK_EOF
   $ cat > quote.py <<NO_CHECK_EOF
   > # let's use quote in comments
@@ -42,6 +45,9 @@
    >     return ( 5+6, 9)
    gratuitous whitespace in () or []
    missing whitespace in expression
+  ./wrong.py:5:
+   >     return 1 + \
+   Use () to wrap long lines in Python, not \
   ./quote.py:5:
    > '"""', 42+1, """and
    missing whitespace in expression