forked from Lephenixnoir/PythonExtra
34d4dab683
The random module's getrandbits() method didn't give a proper error message when calling it with a value that was outside of the range of 1-32, which can lead to confusion using this function (which under CPython can accept numbers larger than 32). Now instead of simply giving a ValueError it gives an error message that states that the number of bits is constrained. Also, since the random module's functions getrandbits() and randint() differ from CPython, tests have been added to describe these differences. For getrandbits the relevant documentation is shown and added to the docs. The same is given for randint method so that the information is more easily found. Finally, since the int object lacks the bit_length() method there is a test for that method also to include within the docs, showing the difference to CPython.
10 lines
241 B
Python
10 lines
241 B
Python
"""
|
|
categories: Types,int
|
|
description: ``bit_length`` method doesn't exist.
|
|
cause: bit_length method is not implemented.
|
|
workaround: Avoid using this method on MicroPython.
|
|
"""
|
|
|
|
x = 255
|
|
print("{} is {} bits long.".format(x, x.bit_length()))
|