Fixed #15053 -- Improved template extending algorithm.

we should keep `versionadded:: 1.7` and have `.. versionchanged:: 1.8` describe what changed in 1.8.