I am dealing with integral
$I=\int_0^{\pi}dx\frac{\sin^2x}{a^2+\sin^2x}.$
I know the answer is
$I=\pi(1-\frac{a}{\sqrt{1+a^2}}).$
However I am having some uncertainty getting there. I know that before plugging in the integration limits the solution looks like
$I= \left[x-\frac{a \tan ^{-1}\left(\frac{\sqrt{1+a^2}}{a} \tan x\right)}{\sqrt{1+a^2}}\right]^{x=\pi}_{x=0}$
but at first sight this would yield merely $\pi$. I can see that the right step to recover the correct solution is to take
$\tan^{-1}\left(\frac{\sqrt{1+a^2}}{a} \tan x\right)\Big\rvert_{x=\pi}=\pi$
however how do I justify this (besides that it yields the correct answer)?