Extend a formula of conditional expectation from finitely to countably generated $\sigma$-algebra I'm reading an exercise in this lecture note, i.e.,

Exercise 2. Suppose that the $\sigma$-algebra $\mathscr{G}$ is finite, that is, suppose that there is a finite measurable partition $B_1, B_2, \ldots, B_n$ of $\Omega$ such that $\mathscr{G}$ is the $\sigma$-algebra generated by the sets $B_i$. Show that for any $X \in L^2(\Omega, \mathscr{F}, P)$,
$$
E(X | \mathscr{G})=\sum_{i=1}^n \frac{E\left(X \mathbf{1}_{B_i}\right)}{P\left(B_i\right)} \mathbf{1}_{B_i} \quad \text {a.s.}
$$

I have found a related lemma from Erhan Çınlar's Probability and Stochastics, i.e.,

Lemma: Let $\mathcal A = (A_i)_{i\in I}$ be a countable partition of $X$ such that $\emptyset \in \mathcal A$. Then
$$
\sigma (\mathcal A) = \left \{ \cup_{i \in J} A_i  \,\middle\vert\, J \subset I  \right\}.
$$

It seems from the Lemma that Exercise 2 extends naturally to countably infinite measurable partition of $\Omega$. Could you confirm if my understanding is correct?
 A: Your understanding is correct.

If we define:$$Y:=\sum_{i\in I}\mathbb{E}\left[X\mid A_{i}\right]\boldsymbol{1}_{A_{i}}$$then $Y$ is measurable wrt $\sigma(\mathcal A)$ and for every $J\subseteq I$:
$$\mathbb{E}[Y\boldsymbol{1}_{\bigcup_{i\in J}A_{i}}]=\mathbb{E}\left[\sum_{i\in J}\mathbb{E}\left[X\mid A_{i}\right]\boldsymbol{1}_{A_{i}}\right]=\sum_{i\in J}\mathbb{E}\left[X\mid A_{i}\right]\mathbb{E}\boldsymbol{1}_{A_{i}}=$$$$\sum_{i\in J}\mathbb{E}\left[X\mid A_{i}\right]P\left(A_{i}\right)=\sum_{i\in J}\mathbb{E}\left(X\boldsymbol{1}_{A_{i}}\right)=\mathbb{E}\left[\sum_{i\in J}X\boldsymbol{1}_{A_{i}}\right]=\mathbb{E}[X\boldsymbol{1}_{\bigcup_{i\in J}A_{i}}]$$
Proved is now that $\mathbb{E}\left[Y\boldsymbol{1}_{A}\right]=\mathbb{E}\left[X\boldsymbol{1}_{A}\right]$ for every $A\in\sigma(\mathcal A)$ and that is enough to conclude that: $$Y=\mathbb E[X\mid \mathcal A]$$

Eventual situations in which $P(A_i)=0$ can be neglected without essential harm.
The lemma looks a bit weird because if $\mathcal A$ is a partition then by definition $\varnothing\notin\mathcal A$. Leaving the condition $\varnothing\in\mathcal A$ out gives no obstacle because we can take $J=\varnothing$ to get $\varnothing$ as an element of $\sigma(\mathcal A)$.
