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
This commit is contained in:
Semyon Proshev
2016-07-26 20:14:37 +03:00
parent 0a675d99a8
commit e313e5151b
4 changed files with 17 additions and 2 deletions
@@ -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()))
@@ -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')
@@ -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();
}