List<String> (@Nullable PyExpression expression) { if (expression == null) return Collections.emptyList(); if (expression instanceof PyBinaryExpression) { final List<String> leftTypes = collectUnionTypes(((PyBinaryExpression)expression).getLeftExpression()); final List<String> rightTypes = collectUnionTypes(((PyBinaryExpression)expression).getRightExpression()); return ContainerUtil.concat(leftTypes, rightTypes); } else if (expression instanceof PyParenthesizedExpression) { return collectUnionTypes(PyPsiUtils.flattenParens(expression)); } else { return Collections.singletonList(expression.getText()); } }