summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bryant <leachim@leachim.info>2012-12-06 17:44:37 +0000
committerMike Bryant <leachim@leachim.info>2012-12-06 17:44:37 +0000
commit19a54ae055682f14a7e7646538f938c959735be3 (patch)
tree2840af27381608bad6ea317a006b3e23ff7b3fce
parentc37940a66c238a5ed8018544948939e394d28458 (diff)
downloadpylint-19a54ae055682f14a7e7646538f938c959735be3.tar.gz
closes #113231. logging checker now looks at instances of Logger classes in addition to the base logging module.
-rw-r--r--ChangeLog3
-rw-r--r--checkers/logging.py13
-rw-r--r--test/input/func_bug113231.py24
-rw-r--r--test/messages/func_bug113231.txt2
4 files changed, 40 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index e3455b5..1658c16 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -24,6 +24,9 @@ ChangeLog for PyLint
* #112728: Add warning E0604 for non-string objects in __all__
(patch by Torsten Marek)
+ * #113231: logging checker now looks at instances of Logger classes
+ in addition to the base logging module. (patch by Mike Bryant)
+
--
* #115580: fix erroneous W0212 (access to protected member) on super call
(patch by Martin Pool)
diff --git a/checkers/logging.py b/checkers/logging.py
index 9092b6c..7e5685d 100644
--- a/checkers/logging.py
+++ b/checkers/logging.py
@@ -80,8 +80,17 @@ class LoggingChecker(checkers.BaseChecker):
def visit_callfunc(self, node):
"""Checks calls to (simple forms of) logging methods."""
if (not isinstance(node.func, astng.Getattr)
- or not isinstance(node.func.expr, astng.Name)
- or node.func.expr.name != self._logging_name):
+ or not isinstance(node.func.expr, astng.Name)):
+ return
+ try:
+ logger_class = [inferred for inferred in node.func.expr.infer() if (
+ isinstance(inferred, astng.Instance)
+ and [ancestor for ancestor in inferred._proxied.ancestors() if (
+ ancestor.name == 'Logger'
+ and ancestor.parent.name == 'logging')])]
+ except astng.exceptions.InferenceError:
+ return
+ if (node.func.expr.name != self._logging_name and not logger_class):
return
self._check_convenience_methods(node)
self._check_log_methods(node)
diff --git a/test/input/func_bug113231.py b/test/input/func_bug113231.py
new file mode 100644
index 0000000..b5b5d8a
--- /dev/null
+++ b/test/input/func_bug113231.py
@@ -0,0 +1,24 @@
+# pylint: disable=E1101
+# pylint: disable=C0103
+# pylint: disable=R0903
+"""test bugfix for #113231 in logging checker
+"""
+
+__revision__ = ''
+
+# Muck up the names in an effort to confuse...
+import logging as renamed_logging
+
+class Logger(object):
+ """Fake logger"""
+ pass
+
+logger = renamed_logging.getLogger(__name__)
+fake_logger = Logger()
+
+# Statements that should be flagged:
+renamed_logging.warn('%s, %s' % (4, 5))
+logger.warn('%s' % 5)
+
+# Statements that should not be flagged:
+fake_logger.warn('%s' % 5)
diff --git a/test/messages/func_bug113231.txt b/test/messages/func_bug113231.txt
new file mode 100644
index 0000000..a9d3f7e
--- /dev/null
+++ b/test/messages/func_bug113231.txt
@@ -0,0 +1,2 @@
+W: 20: Specify string format arguments as logging function parameters
+W: 21: Specify string format arguments as logging function parameters