CPython allows this and it's a simple generalisation of the existing code which just supported str/bytes. Fixes issue #5704.