Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Unified Diff: third_party/pylint/checkers/stdlib.py

Issue 753543006: pylint: upgrade to 1.4.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/pylint/checkers/spelling.py ('k') | third_party/pylint/checkers/strings.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/pylint/checkers/stdlib.py
diff --git a/third_party/pylint/checkers/stdlib.py b/third_party/pylint/checkers/stdlib.py
index 9913e99a906ed5512e45d584d698ebe7ca7feb3c..d8b5fdec4e1f7eeb1312b2e0ccbb83c97b29c3cc 100644
--- a/third_party/pylint/checkers/stdlib.py
+++ b/third_party/pylint/checkers/stdlib.py
@@ -19,6 +19,7 @@ import re
import sys
import astroid
+from astroid.bases import Instance
from pylint.interfaces import IAstroidChecker
from pylint.checkers import BaseChecker
@@ -31,15 +32,22 @@ if sys.version_info >= (3, 0):
else:
OPEN_MODULE = '__builtin__'
-class OpenModeChecker(BaseChecker):
+class StdlibChecker(BaseChecker):
__implements__ = (IAstroidChecker,)
- name = 'open_mode'
+ name = 'stdlib'
msgs = {
'W1501': ('"%s" is not a valid mode for open.',
'bad-open-mode',
'Python supports: r, w, a modes with b, +, and U options. '
'See http://docs.python.org/2/library/functions.html#open'),
+ 'W1502': ('Using datetime.time in a boolean context.',
+ 'boolean-datetime',
+ 'Using datetetime.time in a boolean context can hide '
+ 'subtle bugs when the time they represent matches '
+ 'midnight UTC. This behaviour was fixed in Python 3.5. '
+ 'See http://bugs.python.org/issue13936 for reference.',
+ {'maxversion': (3, 5)}),
}
@utils.check_messages('bad-open-mode')
@@ -51,6 +59,36 @@ class OpenModeChecker(BaseChecker):
if getattr(node.func, 'name', None) in ('open', 'file'):
self._check_open_mode(node)
+ @utils.check_messages('boolean-datetime')
+ def visit_unaryop(self, node):
+ if node.op == 'not':
+ self._check_datetime(node.operand)
+
+ @utils.check_messages('boolean-datetime')
+ def visit_if(self, node):
+ self._check_datetime(node.test)
+
+ @utils.check_messages('boolean-datetime')
+ def visit_ifexp(self, node):
+ self._check_datetime(node.test)
+
+ @utils.check_messages('boolean-datetime')
+ def visit_boolop(self, node):
+ for value in node.values:
+ self._check_datetime(value)
+
+ def _check_datetime(self, node):
+ """ Check that a datetime was infered.
+ If so, emit boolean-datetime warning.
+ """
+ try:
+ infered = next(node.infer())
+ except astroid.InferenceError:
+ return
+ if (isinstance(infered, Instance) and
+ infered.qname() == 'datetime.time'):
+ self.add_message('boolean-datetime', node=node)
+
def _check_open_mode(self, node):
"""Check that the mode argument of an open or file call is valid."""
try:
@@ -66,5 +104,5 @@ class OpenModeChecker(BaseChecker):
def register(linter):
"""required method to auto register this checker """
- linter.register_checker(OpenModeChecker(linter))
+ linter.register_checker(StdlibChecker(linter))
« no previous file with comments | « third_party/pylint/checkers/spelling.py ('k') | third_party/pylint/checkers/strings.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698