private static boolean isSyntacticallyValidAnnotation(@NotNull PyExpression expression) {
    return PsiTreeUtil.processElements(expression, element -> {
      // Check only composite elements
      if (element instanceof ASTDelegatePsiElement) {
        if (!VALID_TYPE_ANNOTATION_ELEMENTS.contains(element.getNode().getElementType())) {
          return false;
        }
        if (element instanceof PyReferenceExpression) {
          // too complex reference expression, e.g. foo[bar].baz
          return ((PyReferenceExpression)element).asQualifiedName() != null;
        }
      }
      return true;
    });
  }
private static boolean isSyntacticallyValidAnnotation(@NotNull PyExpression expression)