I have recently updated to Python 3.11 from 3.8 and started getting warnings about randrange() only accepting integers as inputs. I thought I was only using integers with the randrange() but I realised that by using scientific notation I always get floats even though I specify integer numbers (e.g., 1e6).
I have no issue with randrange() accepting only integers – it makes sense – but scientific notation is mainly meant for convenience and therefore having to write “int(1e6)” to get integers is not helpful. One might as well write 1000000. So why are numbers in scientific notation type-cast?
(I have noticed that some would want int() to accept scientific notation strings but that is not my issue)
Obviously, this is not a huge problem, simply annoying, and so I was wondering: what was the reasoning behind the decision to assume all numbers in scientific notation are floats? Is there a PEP for this? Could this be changed in the future?
Yep, plus that’s not a literal any more - this actually is a type cast. (Technically 10**23 isn’t a literal either, but thanks to constant folding, it behaves like one - it’s as fast and reliable as a literal.)