changeset 11341:920a783e5f91

check-code: fix check for any/all function The old check would only detect any/all at the beginning of a line. The regexp was probably just modeled after the preceding regexp which (correctly) finds the 'with' keyword at the beginning of a line. We now complain about 'any(' and 'all(' anywhere in a line, unless it is preceded by 'def'. This allows us to define our own compatibility wrapper in util and use 'util.any(' in the code.
author Martin Geisler <mg@aragost.com>
date Tue, 15 Jun 2010 09:51:52 +0200
parents 938fefb57db5
children aecabad8dd7a
files contrib/check-code.py tests/test-check-code tests/test-check-code.out
diffstat 3 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/check-code.py	Mon Jun 14 16:56:20 2010 -0300
+++ b/contrib/check-code.py	Tue Jun 15 09:51:52 2010 +0200
@@ -92,7 +92,7 @@
     (r'[\x80-\xff]', "non-ASCII character literal"),
     (r'("\')\.format\(', "str.format() not available in Python 2.4"),
     (r'^\s*with\s+', "with not available in Python 2.4"),
-    (r'^\s*(any|all)\(', "any/all not available in Python 2.4"),
+    (r'(?<!def)\s+(any|all)\(', "any/all not available in Python 2.4"),
     (r'if\s.*\selse', "if ... else form not available in Python 2.4"),
     (r'([\(\[]\s\S)|(\S\s[\)\]])', "gratuitous whitespace in () or []"),
 #    (r'\s\s=', "gratuitous whitespace before ="),
--- a/tests/test-check-code	Mon Jun 14 16:56:20 2010 -0300
+++ b/tests/test-check-code	Tue Jun 15 09:51:52 2010 +0200
@@ -22,5 +22,15 @@
 a, '\\\\\\\\', "\\\\\\" x-2", "c-1"
 EOF
 
+cat > non-py24.py <<EOF
+# Using builtins that does not exist in Python 2.4
+if any():
+    x = all()
+
+# Do not complain about our own definition
+def any(x):
+    pass
+EOF
+
 check_code=`dirname $0`/../contrib/check-code.py
-${check_code} ./wrong.py ./correct.py ./quote.py
+${check_code} ./wrong.py ./correct.py ./quote.py ./non-py24.py
--- a/tests/test-check-code.out	Mon Jun 14 16:56:20 2010 -0300
+++ b/tests/test-check-code.out	Tue Jun 15 09:51:52 2010 +0200
@@ -11,3 +11,9 @@
 ./quote.py:5:
  > '"""', 42+1, """and
  missing whitespace in expression
+./non-py24.py:2:
+ > if any():
+ any/all not available in Python 2.4
+./non-py24.py:3:
+ >     x = all()
+ any/all not available in Python 2.4