This generalises and simplifies the code and follows CPython behaviour. See similar change for floats in a07fc5b640. Signed-off-by: Damien George <damien@micropython.org>
a07fc5b640