Continuity over a compact subset of a metric space implies continuity everywhere Let $f: (X, d_X) \rightarrow (Y, d_Y)$ be a function from metric spaces. If $f$ restricted to any compact subset of $X$ is continuous, then $f$ must be continuous everywhere.
Should I proceed with the characterization of continuity that the preimage of a closed set is closed? Except we are working with compact subsets of the domain, not the range, and it is not true that closed sets are mapped to closed sets, so how can I get continuity of $f$ everywhere?
I am also thinking about the fact that compactness is equivalent to sequential compactness in a metric space. Would this help?
 A: Let $C$ be a closed subset of $Y$ and let $x\in\overline{f^{-1}(C)}$.
There exists a sequence $(x_n)$ in $f^{-1}(C)$ that converges to $x$. The set $S=\{x_n:n\ge0\}\cup\{x\}$ is compact, so the restriction of $f$ to $S$ is continuous. Therefore $\lim_{n\to\infty}f(x_n)=f(x)$ and, since $C$ is closed, we have that $f(x)\in C$. Hence $x\in f^{-1}(C)$.
A: Hint: a convergent sequence together with its limit point is a compact set.
Further hint: Also, continuity at a point is equivalent to continuity along (all) sequences converging to that point.
A: This is false, but as I've commented I believe it is due only to a typo in the original post. The true statement would be to say
If $f$ restricted to every compact subset of $X$ is continuous, then $f$ must be continuous everywhere.
The trivial counter example to your original statement would be something along the lines of: let $f : \mathbb{R} \rightarrow \mathbb{R}$ be identically the zero map on $[0, 1]$, and elsewhere $f(r) = 0$ for every rational number $r$ and $f(x) = 1$ for every irrational number $x$.
A: egreg's solution is elementary and great. In fact something more is true. A space $X$ is said to be compactly generated if a set $A$ is open if $A\cap C$ is open in $C$ for all compact subset $C$ of $X$. One known fact is that if a space $X$ is first countable, then $X$ is compactly generated space. In particular, metric space is compactly generated space. Now let $V\subset Y$ be an open set. For compact subset $C\subset X$, $f^{-1}(V)\cap C = (f|_C)^{-1}(V)$ is open in $C$ by assumption. Since $X$ is compactly generated, this implies $f^{-1}(V)$ is open which shows the continuity of $f$.
