Cauchy's Residue Theorem on a Singularity Outside a Contour I recently ran into the following exercise:

Evaluate
  $$\oint_\Gamma\frac{\cos z}{(z-\pi)^2}dz,$$where $\Gamma$ is a complete circuit of the circle $|z|=1$.

Clearly, the singularity lies outside the contour:
                                    
However, recall Cauchy's Residue Theorem:

If $\Gamma$ is a simple closed positively oriented contour and $f$ is analytic inside and on $\Gamma$ except at the points $z_1$, $z_2$, ..., $z_n$, then
  $$\int_\Gamma f(z)dz=2\pi i\sum_{j=1}^{n}\text{Res}(z_j),$$
  where
  $$\text{Res}(f;z_0)=\lim_{z\to z_0}\frac{1}{(m-1)!}\frac{d^{m-1}}{dz^{m-1}}[(z-z_0)^mf(z)].$$

If I use this to evaluate the integral, I will have that
$$\text{Res}(f;\pi)=\lim_{z\to\pi}\frac{d}{dz}[\cos z]=0,$$and hence the value of the integral will evaluate to $0$, which is the correct answer.
Is this purely coincidental? Because, as I understand it, for Cauchy's theorem to hold, the singularities must lie within the contour (or perhaps not?). Thanks in advance!
 A: $$\oint_\Gamma\frac{\cos z}{(z-\pi)^2}dz=0$$
by Cauchy-Goursat Theorem because the function being integrated is holomorphic/analytic on $\Gamma$. 
That's it - no residues need to be computed!
A: Actually, thats a coincidence.
In principle, you got it right - the integral is zero because your function is holomorphic on the whole given region of integration (the unit ball - it has no poles in it, right?).
Also, your last assertions - the Res calculation - means exactly that the singularity at $\pi$ is not "really a singularity" - it is called, I believe, removable singularity, and thus is not a pole (nor an essential singularity). This means that, even if you took some curve "embracing" the point $\pi$, the integral would be zero (provided the curve be closed).
EDIT: Summing up, yes, you were right when you said that the poles should be inside the contour. And yes, it is a coincidence that the "residue" is zero (since it is not a residue actually, as the point is not a pole!)
A: You don't have to do anything to evaluate your integral, because $\cos(z)/(z-\pi)^2$ is holomorphic on the unit disc. So by Cauchy's theorem for a disk (or whichever more general variant you'd prefer), the integral is zero. You can also evaluate this using the residue theorem, but none of the residues are inside the disk so once again you get zero.
The function does indeed have a pole of order $2$ at $\pi$ and the residue is $0$. This does not mean that the function has a removable singularity at the pole, it just means that the function has an analytic antiderivative in some punctured disk about $\pi$.
