# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 2011-05-02 08:11:24 # Node ID 1b4b82063ce2c0a918dfb7dfa5537ed665dd5894 # Parent 135e244776f007d55619752bb863d4a6f3081984 check-code: disallow calling opener(...).read() and opener(..).write() diff --git a/contrib/check-code.py b/contrib/check-code.py --- a/contrib/check-code.py +++ b/contrib/check-code.py @@ -161,6 +161,18 @@ pypats = [ (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"), + (r'opener\([^)]*\).read\(', + "use opener.read() instead"), + (r'opener\([^)]*\).write\(', + "use opener.write() instead"), + (r'[\s\(](open|file)\([^)]*\)\.read\(', + "use util.readfile() instead"), + (r'[\s\(](open|file)\([^)]*\)\.write\(', + "use util.readfile() instead"), + (r'^[\s\(]*(open(er)?|file)\([^)]*\)', + "always assign an opened file to a variable, and close it afterwards"), + (r'[\s\(](open|file)\([^)]*\)\.', + "always assign an opened file to a variable, and close it afterwards"), ], # warnings [