Fix regression in pkg.latest_version

This fixes a regression introduced in bd72e44. Resolves #7257.