If we cannot infer the type of '__new__', return a weak class type (PY-10893)

This commit is contained in:
Andrey Vlasovskikh
2013-09-26 19:39:00 +04:00
parent feea24c68c
commit 539ba37e9e
4 changed files with 23 additions and 0 deletions
@@ -408,6 +408,12 @@ public class PyCallExpressionHelper {
if (t != null && !(t instanceof PyNoneType)) {
return t;
}
if (cls != null && t == null) {
final PyFunction newMethod = cls.findMethodByName(PyNames.NEW, true);
if (newMethod != null && !PyBuiltinCache.getInstance(call).hasInBuiltins(newMethod)) {
return PyUnionType.createWeakType(new PyClassTypeImpl(cls, false));
}
}
}
if (cls != null) {
return new PyClassTypeImpl(cls, false);
@@ -0,0 +1,4 @@
from b import C
c = C()
c.foo()
@@ -0,0 +1,8 @@
class C(object):
def __new__(cls):
return D()
class D(object):
def foo(self):
pass
@@ -298,6 +298,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyTestCase {
doMultiFileTest("a.py");
}
// PY-10893
public void testCustomNewReturnInAnotherModule() {
doMultiFileTest("a.py");
}
private void doTest() {
myFixture.configureByFile(TEST_DIRECTORY + getTestName(true) + ".py");
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);