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

Dan Villiom Podlaski Christiansen danchr at gmail.com
Tue Dec 7 10:26:45 CST 2010


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1291739155 -3600
# Node ID 383e7983d60a59e658f6fb8a5228eef4925f6623
# Parent  1104f9c69e8d18f666bd9e7072b0fd98ec8e2c56
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
@@ -152,6 +152,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'open\([^)]*\)\.read\(',
+     "use util.readfile() instead"),
+    (r'open\([^)]*\)\.write\(',
+     "use util.readfile() instead"),
+    (r'^\s*open(er)?\([^)]*\)',
+     "always assign an opened file to a variable, and close it afterwards"),
+    (r'open\([^)]*\)\.',
+     "always assign an opened file to a variable, and close it afterwards"),
 ]
 
 pyfilters = [


More information about the Mercurial-devel mailing list