Hartshorne on pg. 70 defines a sheaf $\mathcal O$ of rings on $\mathrm{Spec}(A)$ to be the set of functions $$s : U \to \bigsqcup_{\mathfrak{p} \in U} A_{\mathfrak{p}},$$ where for each $\mathfrak{p}$, $s(\mathfrak{p})\in A_{\mathfrak{p}}$ and for any $\mathfrak{p}\in U$, there is a neighborhood $V$ of $\mathfrak{p}$ in $U$ and elements $a, f \in A$ such that for all $\mathfrak{q}$ in $V$, $f \notin \mathfrak{q}$ and $s(\mathfrak{q})=\frac af \in A_{\mathfrak{q}}$.
Question: What is the motivation for including a disjoint union of the localizations of the ring $A$? Why isn't it a simple union?
The idea here is that Hartshorne wants to construct a type of functions.
The first thing to note is that functions on sets themselves can be expressed as a kind of section. In particular, there is a bijective correspondence between
The corresponding terms are related by the identity $s(x) = (x, f(x))$.
Since these two notions are in bijective correspondence, practical language tends not to distinguish them. If you write a function where a section was expected, you substitute the corresponding section. And vice versa.
In particular, given such an $h$, what we mean by writing $h(x)$ depends on whether the context demands an element of $X \times Y$ or an element of $Y$.
The given situation is more awkward, since we need a notion of function where the codomain isn't fixed!
In this situation, its easier to describe the desired notion as sections of the bundle
$$ \bigsqcup_\mathfrak{p} A_\mathfrak{p} \to |\mathrm{Spec}(A)| $$
(where I use $|\cdot|$ to indicate that I'm specifically referring to its set of points)
The same ambiguity of language mentioned in the previous section apply here. If we're given a thing $h$:
This sort of construction and notation appears more generally in type theory as the notion of a dependent sum.