There are a few common notations in mathematics where an object is used as a function, but it hides a declaration of an assumption.
One example is the line integral, consider (A0), the proposition $X = \oint_{\omega} y\,dz$ . This is actually two propositions, one hiding in the other:
$$X = \int_\omega y\,dz \tag{A1}$$
$$\omega \text{ is a closed manifold } \tag{A2}$$
Suppose you were to assume (A0), derive some results, and then later add the assumption (A3) that $\omega$ is no longer a closer manifold. Your results would be vacuous, since even though (A2) was never explicitly stated, it contradicts (A3).
...
Partial derivatives are another example of a function that hides an assumption. The assumption (a0) that $x = \frac{\partial y} {\partial z}$ is actually two (or more) propositions:
$$x = \frac {dy}{dz} \tag{a1}$$
$$0 = \frac {d\text{ you have to guess these variables} } {dz} \tag{a2}$$
In your example, the formula $\frac{\partial \text{ stuff}}{\partial p}$ is hiding the assumption that $\frac{d q}{d p} = 0$. The further addtion of $p + q = 1$, and thus $\frac{dp}{dq} = 1$ makes the final result vacuous, as you observed by the fact that you can get two different answers-- if you take what he wrote literally.
This is one of those situations where a pedantic person has to be told "read what I meant, not what I wrote". The common practice of writing mathematics to be easily read rather than absolutely pedantically perfect is what makes the study tolerable, although it makes things like peer review very long painful processes of repeatedly asking "what did you really mean here?".
The author meant for you to infer that there is a way the derivation could be done which is correct. Effectively, first you derive (d3):
Consider a functions
$$F_n(x,y) = \sum_{j=0}^{n} j {n\choose j} x^{j}y^{n-j} \tag{d1}$$
$$G_n(x,y) = \sum_{j=0}^{n} {n\choose j} x^{j}y^{n-j} \tag{d2}$$
$$x \frac{dG_n}{dx} = F_n \tag{d3}$$
Then you apply (d3) to the case of the binomial expectation. (d3) is derived just as a statement about functions, so $x$ and $y$ have no meaning outside of (d3) and thus the additional assumption $p + q = 1$ has nothing to contradict. Actually writing things out that way is tedious though, so except for the few people who are interested in formal logic a blind eye tends to be turned.