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

Dan Villiom Podlaski Christiansen danchr at gmail.com
Fri Dec 24 18:35:36 CST 2010


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1293200581 -3600
# Node ID d281ff54afa4e11534aee921102706c477c13322
# Parent  b5f38c305372050460801060e788391f9105c502
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