@Override public PyType getReferenceType( @NotNull PsiElement referenceTarget, TypeEvalContext context, @Nullable PsiElement anchor) { if (referenceTarget instanceof PyTargetExpression) { final PyTargetExpression target = (PyTargetExpression) referenceTarget; if (context.maySwitchToAST(target)) { // XXX: Requires switching from stub to AST final PyAnnotation annotation = target.getAnnotation(); if (annotation != null) { final PyExpression value = annotation.getValue(); if (value != null) { return getType(value, new Context(context)); } return null; } } final String comment = target.getTypeCommentAnnotation(); if (comment != null) { final PyType type = getStringBasedType(comment, referenceTarget, new Context(context)); if (type instanceof PyTupleType) { final PyTupleExpression tupleExpr = PsiTreeUtil.getParentOfType(target, PyTupleExpression.class); if (tupleExpr != null) { return PyTypeChecker.getTargetTypeFromTupleAssignment( target, tupleExpr, (PyTupleType) type); } } return type; } } return null; }