check-code: add a check for the next() builtin, which was new in 2.6 stable
authorAugie Fackler <raf@durin42.com>
Thu, 25 Jul 2013 10:44:51 -0400
branchstable
changeset 19501 725507cd5216
parent 19500 a96565abbd59
child 19502 8704477ad3b6
check-code: add a check for the next() builtin, which was new in 2.6
contrib/check-code.py
tests/test-check-code.t
--- a/contrib/check-code.py	Thu Jul 25 10:42:36 2013 -0400
+++ b/contrib/check-code.py	Thu Jul 25 10:44:51 2013 -0400
@@ -173,6 +173,8 @@
     (r'^\s+(\w|\.)+=\w[^,()\n]*$', "missing whitespace in assignment"),
     (r'(\s+)try:\n((?:\n|\1\s.*\n)+?)\1except.*?:\n'
      r'((?:\n|\1\s.*\n)+?)\1finally:', 'no try/except/finally in Python 2.4'),
+    (r'(?<!def)(\s+|^|\()next\(.+\)',
+     'no next(foo) in Python 2.4 and 2.5, use foo.next() instead'),
     (r'(\s+)try:\n((?:\n|\1\s.*\n)*?)\1\s*yield\b.*?'
      r'((?:\n|\1\s.*\n)+?)\1finally:',
      'no yield inside try/finally in Python 2.4'),
--- a/tests/test-check-code.t	Thu Jul 25 10:42:36 2013 -0400
+++ b/tests/test-check-code.t	Thu Jul 25 10:44:51 2013 -0400
@@ -22,6 +22,13 @@
   > if any():
   >     x = all()
   >     y = format(x)
+  >     # next(generator) is new in 2.6
+  >     z = next(x)
+  >     # but generator.next() is okay
+  >     x.next()
+  >     # and we can make our own next
+  >     def next(stuff):
+  >         pass
   > 
   > # Do not complain about our own definition
   > def any(x):
@@ -94,13 +101,16 @@
   ./non-py24.py:4:
    >     y = format(x)
    any/all/format not available in Python 2.4
-  ./non-py24.py:11:
+  ./non-py24.py:6:
+   >     z = next(x)
+   no next(foo) in Python 2.4 and 2.5, use foo.next() instead
+  ./non-py24.py:18:
    >     try:
    no try/except/finally in Python 2.4
-  ./non-py24.py:28:
+  ./non-py24.py:35:
    >     try:
    no yield inside try/finally in Python 2.4
-  ./non-py24.py:33:
+  ./non-py24.py:40:
    >     try:
    no yield inside try/finally in Python 2.4
   ./classstyle.py:4: