Ag.algebraic Geometry – Error in Hartshorne Exercise II.1.1?

It's really a basic question, but let me spell it out. Exercise 1.1 of the second chapter of Hartshorne's algebraic geometry asks to prove that the sheaf associated with the pre-leaf sending each open subset of a topological space $ X $ to a fixed abelian group $ A $ is the sheaf of continuous functions of the open subsets of $ X $ at $ A $, or $ A $ is equipped with discrete topology.

I usually prove this fact in the following way. First writing $ mathcal {A} $ for sending presheaf $ U subseteq X $ open non-empty subset to $ A $, and $ mathcal {A ^ prime} $ the sending of the wreath $ U $ to the set of continuous functions $ f: U rightarrow A $ or $ A $ has the discrete topology. Now I define a map $ theta: mathcal {A} (U) rightarrow mathcal {A ^ prime} (U) $ who sends the item $ a in A $ to the constant function $ mathbf {a}: U rightarrow A $ send each point of $ U $ at $ a $. Then, if I have a map of presheaves $ phi: mathcal {A} rightarrow mathcal {G} $, I discuss this way. Let me consider $ f in mathcal {A} ^ premium (U) $, and write $ U = bigsqcup_ {i in I} U_i $, where the $ U_i $are the connected components of $ U $. Then define $ a_i: = f (U_i) $, which is well defined by continuity, then defines $ psi_ {| U_i}: mathcal {A} ^ { prime} (U_i) rightarrow mathcal {G} (U_i) $ By sending $ f_ {| U_ {i}} $ at $ b_i: = phi (a_i) $. By the property of sheaf of $ mathcal {G} $, all these sections stick together to define a section $ b in mathcal {G} (U) $. Now, just define $ psi_ {| U} (f) = b $.

Now, what's wrong with that? Well, the problem is that at one point I define morphism $ psi_ {U} $ via his restriction to $ U_i $. The problem is that without any hypothesis on the topological space that I consider, maybe $ mathcal {A} ^ prime (U_i) $ is not even defined. In fact, if $ X $ is arbitrary, nothing says that the connected components are open. Think about the situation of $ mathbb {Q} $ with the usual topology. Therefore, if I assume a condition of $ X $, for example. that it's connected locally, my evidence works, but what if I suppose that $ X $ is arbitrary (as does Hartshorne)?