This comes from #1363 ; I just stole it from there because I needed it, but once #1363 is merged I'll remove my version