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

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

Issue 776883002: pylint: upgrade to 1.4.0 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
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
===================================================================
--- third_party/pylint/checkers/stdlib.py (revision 293207)
+++ third_party/pylint/checkers/stdlib.py (working copy)
@@ -19,6 +19,7 @@
import sys
import astroid
+from astroid.bases import Instance
from pylint.interfaces import IAstroidChecker
from pylint.checkers import BaseChecker
@@ -31,9 +32,9 @@
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.',
@@ -40,6 +41,13 @@
'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 @@
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 @@
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