# HG changeset patch # User Augie Fackler # Date 1357066701 21600 # Node ID c582a71457e5daaa973442b3efd1cc6336f1cc1e # Parent f614543733b6780c8b3faf9a01d11cf1e5d9fb9c check-code: disallow two-argument form of raise Using this old form makes any attempt to port to Python 3 harder, and the new syntax is supported in 2.4 already. diff -r f614543733b6 -r c582a71457e5 contrib/check-code.py --- a/contrib/check-code.py Tue Jan 01 13:25:07 2013 -0600 +++ b/contrib/check-code.py Tue Jan 01 12:58:21 2013 -0600 @@ -185,6 +185,8 @@ (r'[^^+=*/!<>&| %-](\s=|=\s)[^= ]', "wrong whitespace around ="), (r'raise Exception', "don't raise generic exceptions"), + (r'raise [^,(]+, (\([^\)]+\)|[^,\(\)]+)$', + "don't use old-style two-argument raise, use Exception(message)"), (r' is\s+(not\s+)?["\'0-9-]', "object comparison with literal"), (r' [=!]=\s+(True|False|None)', "comparison with singleton, use 'is' or 'is not' instead"), diff -r f614543733b6 -r c582a71457e5 tests/test-check-code.t --- a/tests/test-check-code.t Tue Jan 01 13:25:07 2013 -0600 +++ b/tests/test-check-code.t Tue Jan 01 12:58:21 2013 -0600 @@ -159,3 +159,14 @@ > except: warning: naked except clause [1] + + $ cat > raise-format.py < raise SomeException, message + > # this next line is okay + > raise SomeException(arg1, arg2) + > EOF + $ "$check_code" raise-format.py + raise-format.py:1: + > raise SomeException, message + don't use old-style two-argument raise, use Exception(message) + [1]