Change sort of registered readers/writers to avoid comparing types

Closes #2312 (also in commit comment to make sure it autocloses)

I could not find a way to test the change to ``io.registry._get_valid_format``.