# HG changeset patch # User Thomas Arendsen Hein # Date 1348050552 -7200 # Node ID efd1a4378b64051b5813dafe1df1776a7893923a # Parent 431e3e827ab08dbb7a40e79af57f271c3928ec07 check-code: catch yield inside try/finally (with tests) This is not allowed in Python 2.4. diff -r 431e3e827ab0 -r efd1a4378b64 contrib/check-code.py --- a/contrib/check-code.py Tue Sep 18 16:30:21 2012 -0700 +++ b/contrib/check-code.py Wed Sep 19 12:29:12 2012 +0200 @@ -137,6 +137,9 @@ (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'(\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'), (r'.{81}', "line too long"), (r' x+[xo][\'"]\n\s+[\'"]x', 'string join across lines with no space'), (r'[^\n]\Z', "no trailing newline"), diff -r 431e3e827ab0 -r efd1a4378b64 tests/test-check-code.t --- a/tests/test-check-code.t Tue Sep 18 16:30:21 2012 -0700 +++ b/tests/test-check-code.t Wed Sep 19 12:29:12 2012 +0200 @@ -43,6 +43,19 @@ > pass > finally: > pass + > + > # yield inside a try/finally block is not allowed in Python 2.4 + > try: + > pass + > yield 1 + > finally: + > pass + > try: + > yield + > pass + > finally: + > pass + > > EOF $ cat > classstyle.py < class newstyle_class(object): @@ -84,6 +97,12 @@ ./non-py24.py:11: > try: no try/except/finally in Python 2.4 + ./non-py24.py:28: + > try: + no yield inside try/finally in Python 2.4 + ./non-py24.py:33: + > try: + no yield inside try/finally in Python 2.4 ./classstyle.py:4: > class oldstyle_class: old-style class, use class foo(object)