Holomorphic function on a connected compact Riemann surface is constant I was trying to solve the following exercise. I wanted to check if my solution was correct/rigorous enough, and ask a question at the end. (The general direction is given in here: holomorphic map between compact Riemann surfaces, and I seem to have expanded out the steps in a detailed way)

Let $h\colon X \rightarrow Y$ be a morphism of Riemann surfaces. Assume that $X$ is connected and $h$ is not constant. Show that the image of $h$ is open in $Y .$ Deduce that $h$ is surjective if we moreover assume that $X$ is non-empty and compact, and $Y$ is connected. This implies that a morphism from a connected compact Riemann surface to a connected non-compact Riemann surface is always constant. In particular, every holomorphic function on a connected compact Riemann surface is constant.

Open mapping theorem: If $U$ is a connected open subset of $\mathbb{C}$, then the image of every non-constant holomorphic function $f: U \rightarrow \mathbb{C}$ is open.

Proof: Let $h\colon X \rightarrow Y$ be such a morphism. Let $O \subset X$ be an open subset of $X$, and we will show $h(O)$ is open. For any $x \in O$, let $(U,\phi)$ be a chart of $O$ containing $x$, and $(V,\psi)$ a chart of $Y$ containing $h(x)$. Then consider the holomorphic map $\psi \circ h \circ \phi^{-1}$ defined on the open set $\phi(U \cap h^{-1}(V))\ni\phi(x)$. Draw an open neighbourhood around $\phi(x)$, and apply $\psi \circ h \circ \phi^{-1}$ to it. The result is an open in $\mathbb{C}$ around $\psi \circ h(x)$, using the open mapping theorem. Composing from the left with $\psi^{-1}$, we obtain an open neighbourhood around $h(x)$. Since this holds for any point $x \in O$, $h(O)$ is open in $Y$.
Now assume that $X$ is connected, non-empty, compact, and $Y$ connected. Let the notation be as above. Then $h(X)$ is compact, non-empty, and connected. As $h$ is an open map, $h(X)$ is open in $Y$. As $h(X)$ is compact, it is closed in Hausdorff space $Y$. As $Y$ is connected, we conclude $h(X) = Y$. Now, if $Y$ is non-compact, a continuous map cannot map a compact space to a non-compact space, so $h$ must be a constant (otherwise we proved it is surjective).

Is my solution correct? Also, I do not understand why this implies that every holomorphic function on a connected compact Riemann surface is constant.
 A: Your solution is correct. For the last part, if you do not understand the explanation given in comments, you could try to prove it by contradiction.
Suppose $f : X \to \mathbb{C}$ is holomorphic with $X$ compact, $f$ non-constant. By open mapping theorem, as you said, $f(X)$ is open in $\mathbb{C}$. But as $f$ is continuous and $X$ compact, $f(X)$ is compact. Hence $f(X)$ closed in $\mathbb{C}$ (since compact subspaces of Hausdorff spaces are closed). By connectedness of $\mathbb{C}$, $f(X) = \mathbb{C}$, and $\mathbb{C}$ is then compact: this is the contradiction.

A more direct way to prove this is using the maximum principle. Suppose $f : X \to \mathbb{C}$ is continuous with $X$ compact. Then $|f| : X \to \mathbb{C}$ is continuous and achieves its maximum at a point $p \in X$. Pick a holomorphic coordinate $z$ around $p$, say $z : U \to X$, with $z(0) = p$, and $U$ connected. Then $f\circ z : U\subset \mathbb{C} \to \mathbb{C}$ is holomorphic, and $|f\circ z| $ has a local maximum at $0$: by the maximum principle, $f\circ z$ is constant. It follows that $f$ is locally constant around $p$.
Now, one can easily show that $f^{-1}(f(p))\subset X$ is open and closed, and by connectedness of $X$, $f$ is constant.
