My textbook provides the following theorem:
"Suppose $f$ is continuous in an open set $D$ and analytic there except possibly at the points of a line segment $L$. Then $f$ is analytic throughout $D$."
The proof of this theorem shows that $\int_{\gamma}f=0$ for every closed rectangle in $D$. The detailed proof is not relevant for now (will provide upon request).
My question is: The statement of the theorem is confusing to me: the assumption is that $f$ is not analytic only at the points of a line segment in $D$. The conclusion is that $f$ is analytic throughout $D$. Does it mean that it is impossible for a function to be analytic in a region except at the points of a line in that region?
This may be pedantic, but: the statement
is not quite right. For example, consider a branch of the logarithm defined on $\mathbb{D}\setminus[-1,0]$, where $\mathbb{D}$ is the open unit disk. Then this branch is analytic on $\mathbb{D} \setminus L$, where $L$ is the line segment $[0,1]$, but it cannot be made analytic on $\mathbb{D}$, no matter how you extend the function to the branch cut.
Indeed, by clever manipulation with Möbius transformations, we can send the branch cut $[-\infty,0]$ to the segment $[-\frac{1}{2},\frac{1}{2}]$, then consider the composition of the above discussed branch of the logarithm and the Möbius transformation. The resulting function will be analytic on $\mathbb{D} \setminus [-\frac{1}{2},\frac{1}{2}]$, but cannot be extended to an analytic function on $\mathbb{D}$.
On the bright side, this is not the statement of the theorem being discussed. The theorem asserts that a continuous function on a domain $D$ that is analytic on $D \setminus L$ must be analytic on all of $D$ (where $L$ is a segment, though this can actually be generalized quite a bit; note that the hypotheses do not assert that the function is not analytic on $L$, only that we don't a priori know that it is analytic on $L$). The hypotheses here are stronger: we require not just analyticity on $D\setminus L$, but also continuity on all of $D$. From this, we get the stronger result.