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