From 565e1307e762d3803c9909ba6f00233b7b887e06 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Wed, 13 Jul 2016 16:51:36 +0300 Subject: [PATCH] PY-20071 Fixed: Nonexistent logger methods should be mark as unresolved PY-19716 Fixed: logger.exception() without arguments doesn't show a warning Skeleton for logging.getLogger was accidentally pushed to primary python-skeletons repo and then was synced with current repo. So there is no skeleton in affected files but tests are based on it. At first logger.getLogger returned union of Logger and RootLogger. RootLogger just inherits Logger and doesn't introduce any additional functionality. But there was a problem with PyArgumentListInspection which doesn't work in case of many callees (e.g. logger.exception). So skeleton was updated to return only logger from logging.getLogger. --- python/helpers/python-skeletons/logging.py | 3 +++ .../MethodsForLoggingExceptions/logging.py | 9 +++++++++ .../methodsForLoggingExceptions.py | 5 +++++ .../NonexistentLoggerMethod/a.py | 4 ++++ .../NonexistentLoggerMethod/logging.py | 6 ++++++ .../inspections/PyArgumentListInspectionTest.java | 10 ++++++++++ .../PyUnresolvedReferencesInspectionTest.java | 5 +++++ 7 files changed, 42 insertions(+) create mode 100644 python/testData/inspections/PyArgumentListInspection/MethodsForLoggingExceptions/logging.py create mode 100644 python/testData/inspections/PyArgumentListInspection/MethodsForLoggingExceptions/methodsForLoggingExceptions.py create mode 100644 python/testData/inspections/PyUnresolvedReferencesInspection/NonexistentLoggerMethod/a.py create mode 100644 python/testData/inspections/PyUnresolvedReferencesInspection/NonexistentLoggerMethod/logging.py diff --git a/python/helpers/python-skeletons/logging.py b/python/helpers/python-skeletons/logging.py index cb25d7aa43b5..f121dbe263c4 100644 --- a/python/helpers/python-skeletons/logging.py +++ b/python/helpers/python-skeletons/logging.py @@ -1,5 +1,8 @@ """Skeleton for 'logging' stdlib module.""" +import logging + + def getLogger(name=None): """ :type name: string diff --git a/python/testData/inspections/PyArgumentListInspection/MethodsForLoggingExceptions/logging.py b/python/testData/inspections/PyArgumentListInspection/MethodsForLoggingExceptions/logging.py new file mode 100644 index 000000000000..205bc4ce65fc --- /dev/null +++ b/python/testData/inspections/PyArgumentListInspection/MethodsForLoggingExceptions/logging.py @@ -0,0 +1,9 @@ +def getLogger(): + pass + +def exception(msg): + pass + +class Logger(object): + def exception(self, msg): + pass \ No newline at end of file diff --git a/python/testData/inspections/PyArgumentListInspection/MethodsForLoggingExceptions/methodsForLoggingExceptions.py b/python/testData/inspections/PyArgumentListInspection/MethodsForLoggingExceptions/methodsForLoggingExceptions.py new file mode 100644 index 000000000000..80adb1ad2032 --- /dev/null +++ b/python/testData/inspections/PyArgumentListInspection/MethodsForLoggingExceptions/methodsForLoggingExceptions.py @@ -0,0 +1,5 @@ +import logging + +logger = logging.getLogger() +logger.exception() +logging.exception() \ No newline at end of file diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/NonexistentLoggerMethod/a.py b/python/testData/inspections/PyUnresolvedReferencesInspection/NonexistentLoggerMethod/a.py new file mode 100644 index 000000000000..b4f337fe5995 --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/NonexistentLoggerMethod/a.py @@ -0,0 +1,4 @@ +import logging + +logger = logging.getLogger() +logger.foobar() \ No newline at end of file diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/NonexistentLoggerMethod/logging.py b/python/testData/inspections/PyUnresolvedReferencesInspection/NonexistentLoggerMethod/logging.py new file mode 100644 index 000000000000..9e6ae8ae6d2d --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/NonexistentLoggerMethod/logging.py @@ -0,0 +1,6 @@ +def getLogger(): + pass + +class Logger(object): + def exception(self, msg): + pass \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java index a0800d50c069..225f3b193ce5 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java @@ -212,6 +212,16 @@ public class PyArgumentListInspectionTest extends PyTestCase { doTest(); } + // PY-19716 + public void testMethodsForLoggingExceptions() { + final String folderPath = "inspections/PyArgumentListInspection/" + getTestName(false) + "/"; + + myFixture.copyDirectoryToProject(folderPath, ""); + myFixture.configureFromTempProjectFile("methodsForLoggingExceptions.py"); + myFixture.enableInspections(PyArgumentListInspection.class); + myFixture.checkHighlighting(true, false, false); + } + // PY-19522 public void testCsvRegisterDialect() { final String folderPath = "inspections/PyArgumentListInspection/" + getTestName(false) + "/"; diff --git a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java index 3b2548bddaeb..197301c6811f 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java @@ -729,6 +729,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase { doTest(); } + // PY-20071 + public void testNonexistentLoggerMethod() { + doMultiFileTest(); + } + @NotNull @Override protected Class getInspectionClass() {