py: More robust int conversion and overflow checking.