Proof of a property of the Poisson bracket I have seen written in many courses of statistical mechanics that, for two functions of the general coordinates and momenta $f(q,p)$ and $g(q,p)$ to satisfy
$$
\{f,g\}=0 \tag{1}
$$
in a 2D phase space
is equivalent to demanding that $f$ (or equivalently $g$) is a pure function of $g$ (respectively $f$) so that one can write:
$$f=F(g(q,p)).\tag{2}$$
I am having trouble to understand why this should be the case. 
 A: (Nice result. I did not know.) 
The correct statement is the following. 
Proposition. Suppose that $f=f(q,p)$ and $g=g(q,p)$ are a pair of smooth functions defined on an open set $\Omega \subset \mathbb R^2$  such that $\{f,g\}=0$ thereon. Then, in a neighborhood of any $(p_0,q_0)\in \Omega$ we can write either $f(p,q) = F(g(p,q))$ or   $g(p,q) = G(f(p,q))$ for some smooth function $F=F(x)$ or $G=G(x)$ depending on the said neighborhood.
Proof. The thesis is true if either $f$ or $g$ is constant around $(p_0,q_0)$ since $F$ or $G$ can be chosen constant in that case. So suppose the at least one of the functions is not constant, say $g$. If $g$ is not constant, at least one derivative of $\partial_p g|_{(q_0,p_0)}$ and   $\partial_q g|_{(q_0,p_0)}$  does not vanish and therefore it does not vanish in a neighborhood of $(q_0,p_0)$ by continuity. Suppose $\partial_q g|_{(q_0,p_0)}\neq 0$ (the remaining cases are similar). Dini's theorem assures that it is possible to write $q= q(g,p)$ in a neighborhood of the said point where $q= q(g,p)$  is smooth and $g$ and $p$ are independent variables. Therefore  $\{f,g\}=0$ can be restated as
$$\frac{\partial f}{\partial p} = \frac{\partial f}{\partial q} \frac{\frac{\partial g}{\partial p} }{\frac{\partial g}{\partial q}} = -\frac{\partial f}{\partial q} \frac{\partial q}{\partial p}\tag{1}\:$$
(I used $g= g(q(g,p),p)$, so taking the total $p$ derivative of both sides since $p$ and $g$ are independent variables: $0 = \frac{\partial g}{\partial q} \frac{\partial q}{\partial p}+ \frac{\partial g}{\partial p}$ and therefore $-\frac{\partial g}{\partial p}/ \frac{\partial g}{\partial q} = \frac{\partial q}{\partial p}$).
Next consider the composite map
$$f^*(g,p) := f(q(g,p),p)\tag{2}$$
Let us compute the $p$-derivative taking (1) into account:
$$\frac{\partial f^*}{\partial p}= \frac{\partial f}{\partial p} +  \frac{\partial f}{\partial q} \frac{\partial q}{\partial p} = -\frac{\partial f}{\partial q} \frac{\partial q}{\partial p} + \frac{\partial f}{\partial q} \frac{\partial q}{\partial p} =0\:.$$ 
So $f^*$ in (2) does not depend on $p$, as a consequence
$$f(q,p) = f^*(g(q,p))\:,$$
as wanted if defining $F:= f^*$. QED
