If reference points to property and property type could not be inferred, stop with "Any", don't do any further processing.

This commit is contained in:
Semyon Proshev
2017-02-15 15:45:53 +03:00
parent 6639247319
commit 8fb5ea7d24
3 changed files with 19 additions and 6 deletions

View File

@@ -238,9 +238,9 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
}
if (qualified) {
final PyType qualifiedReferenceType = getQualifiedReferenceType(context);
final Ref<PyType> qualifiedReferenceType = getQualifiedReferenceType(context);
if (qualifiedReferenceType != null) {
return qualifiedReferenceType;
return qualifiedReferenceType.get();
}
}
@@ -256,22 +256,22 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
}
@Nullable
private PyType getQualifiedReferenceType(@NotNull TypeEvalContext context) {
private Ref<PyType> getQualifiedReferenceType(@NotNull TypeEvalContext context) {
if (!context.maySwitchToAST(this)) {
return null;
}
final PyType maybe_type = PyUtil.getSpecialAttributeType(this, context);
if (maybe_type != null) return maybe_type;
if (maybe_type != null) return Ref.create(maybe_type);
final Ref<PyType> typeOfProperty = getTypeOfProperty(context);
if (typeOfProperty != null) {
return typeOfProperty.get();
return typeOfProperty;
}
final PyType typeByControlFlow = getQualifiedReferenceTypeByControlFlow(context);
if (typeByControlFlow != null) {
return typeByControlFlow;
return Ref.create(typeByControlFlow);
}
return null;

View File

@@ -0,0 +1,2 @@
def get_class():
return str

View File

@@ -1665,6 +1665,17 @@ public class PyTypeTest extends PyTestCase {
" print(expr)");
}
public void testImportedPropertyResult() {
doMultiFileTest("Any",
"from .temporary import get_class\n" +
"class Example:\n" +
" def __init__(self):\n" +
" expr = self.ins_class\n" +
" @property\n" +
" def ins_class(self):\n" +
" return get_class()");
}
private static List<TypeEvalContext> getTypeEvalContexts(@NotNull PyExpression element) {
return ImmutableList.of(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()).withTracing(),
TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()).withTracing());