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

Dan Villiom Podlaski Christiansen danchr at gmail.com
Sun Dec 26 05:51:24 CST 2010


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1293364216 -3600
# Node ID 86eb1e8cce41ed6423698682adec8f9c71498dfd
# Parent  348af603fdd6d79ec109259e9a394673b2069456
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
@@ -154,6 +154,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