summaryrefslogtreecommitdiff
path: root/checkers/stdlib.py
diff options
context:
space:
mode:
authorCosmin Poieana <cmin@ropython.org>2014-12-05 22:21:43 +0200
committerCosmin Poieana <cmin@ropython.org>2014-12-05 22:21:43 +0200
commit71a57315275cbc4f8f6a1eb3504735add10f3130 (patch)
tree7da2204285a82f82a902942bd1c269b80670a885 /checkers/stdlib.py
parent4598e5f719661cb2f40548fa14f1bcfda87d7a6d (diff)
downloadpylint-git-71a57315275cbc4f8f6a1eb3504735add10f3130.tar.gz
Fix 2.x open mode check; Add more tests
--HG-- branch : open_mode
Diffstat (limited to 'checkers/stdlib.py')
-rw-r--r--checkers/stdlib.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/checkers/stdlib.py b/checkers/stdlib.py
index aafb97041..6d4c89c3c 100644
--- a/checkers/stdlib.py
+++ b/checkers/stdlib.py
@@ -57,6 +57,8 @@ def _check_mode_str(mode):
if writing or appending or creating and six.PY3:
return False
reading = True
+ if not six.PY3:
+ binary = True
if text and binary:
return False
total = reading + writing + appending + (creating if six.PY3 else 0)
@@ -64,8 +66,12 @@ def _check_mode_str(mode):
return False
if not (reading or writing or appending or creating and six.PY3):
return False
- # 2.x constraints
+ # other 2.x constraints
if not six.PY3:
+ if "U" in mode:
+ mode = mode.replace("U", "")
+ if "r" not in mode:
+ mode = "r" + mode
return mode[0] in ("r", "w", "a", "U")
return True
@@ -77,7 +83,8 @@ class StdlibChecker(BaseChecker):
msgs = {
'W1501': ('"%s" is not a valid mode for open.',
'bad-open-mode',
- 'Python supports: r, w, a modes with b, +, and U options. '
+ 'Python supports: r, w, a[, x] modes with b, +, '
+ 'and U (only with r) options. '
'See http://docs.python.org/2/library/functions.html#open'),
'W1502': ('Using datetime.time in a boolean context.',
'boolean-datetime',