[PATCH 4 of 4] check-code: disallow calling opener(...).read() and opener(..).write()

Dan Villiom Podlaski Christiansen danchr at gmail.com
Mon May 2 03:11:49 CDT 2011


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1304323884 -7200
# Node ID 1507f659f873769d9ab9b2abab2136997e7e5e1d
# Parent  83413f43a7e16e0aeb17e6ee0527731432c25a1b
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
   [


More information about the Mercurial-devel mailing list