From e313e5151be88f32b544d2b3883bc13a83451259 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Fri, 22 Jul 2016 15:22:51 +0300 Subject: [PATCH] PY-20038 Fixed: "Call to __init__ of super class is missed" inspection if super is used with __class__ Update PyMissingConstructorInspection to honour __class__ as a first arg of super(...).__init__ call --- .../inspections/PyMissingConstructorInspection.java | 3 ++- .../{dunderClass.py => explicitDunderClass.py} | 0 .../implicitDunderClass.py | 9 +++++++++ .../python/inspections/PyMissingConstructorTest.java | 7 ++++++- 4 files changed, 17 insertions(+), 2 deletions(-) rename python/testData/inspections/PyMissingConstructorInspection/{dunderClass.py => explicitDunderClass.py} (100%) create mode 100644 python/testData/inspections/PyMissingConstructorInspection/implicitDunderClass.py diff --git a/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java b/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java index 6126168486e4..f27981488049 100644 --- a/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java @@ -140,7 +140,8 @@ public class PyMissingConstructorInspection extends PyInspection { String firstArg = args[0].getText(); final String qualifiedName = cl.getQualifiedName(); if (firstArg.equals(cl.getName()) || firstArg.equals(CANONICAL_SELF+"."+ __CLASS__) || - (qualifiedName != null && qualifiedName.endsWith(firstArg))) + (qualifiedName != null && qualifiedName.endsWith(firstArg)) || + (LanguageLevel.forElement(cl).isAtLeast(LanguageLevel.PYTHON30) && firstArg.equals(__CLASS__))) return true; for (PyClass s : cl.getAncestorClasses(myTypeEvalContext)) { if (firstArg.equals(s.getName())) diff --git a/python/testData/inspections/PyMissingConstructorInspection/dunderClass.py b/python/testData/inspections/PyMissingConstructorInspection/explicitDunderClass.py similarity index 100% rename from python/testData/inspections/PyMissingConstructorInspection/dunderClass.py rename to python/testData/inspections/PyMissingConstructorInspection/explicitDunderClass.py diff --git a/python/testData/inspections/PyMissingConstructorInspection/implicitDunderClass.py b/python/testData/inspections/PyMissingConstructorInspection/implicitDunderClass.py new file mode 100644 index 000000000000..a635c91d479d --- /dev/null +++ b/python/testData/inspections/PyMissingConstructorInspection/implicitDunderClass.py @@ -0,0 +1,9 @@ +class First: + def __init__(self): + print('First inited') + + +class Second(First): + def __init__(self): + super(__class__, self).__init__() + print('Second inited') \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/PyMissingConstructorTest.java b/python/testSrc/com/jetbrains/python/inspections/PyMissingConstructorTest.java index 374e317bb097..cc9fe136a631 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyMissingConstructorTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyMissingConstructorTest.java @@ -44,7 +44,12 @@ public class PyMissingConstructorTest extends PyTestCase { doTest(); } - public void testDunderClass() { // PY-4038 + public void testExplicitDunderClass() { // PY-4038 + doTest(); + } + + public void testImplicitDunderClass() { // PY-20038 + setLanguageLevel(LanguageLevel.PYTHON30); doTest(); }