Skip to content

Commit 9349972

Browse files
authored
gh-143700: document secrets.DEFAULT_ENTROPY as an opaque value (#144568)
1 parent 6665115 commit 9349972

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

Doc/library/secrets.rst

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,44 @@ The :mod:`!secrets` module provides functions for generating secure
6262
tokens, suitable for applications such as password resets,
6363
hard-to-guess URLs, and similar.
6464

65-
.. function:: token_bytes([nbytes=None])
65+
.. function:: token_bytes(nbytes=None)
6666

6767
Return a random byte string containing *nbytes* number of bytes.
68-
If *nbytes* is ``None`` or not supplied, a reasonable default is
69-
used.
68+
69+
If *nbytes* is not specified or ``None``, :const:`DEFAULT_ENTROPY`
70+
is used instead.
7071

7172
.. doctest::
7273

73-
>>> token_bytes(16) #doctest:+SKIP
74+
>>> token_bytes(16) # doctest: +SKIP
7475
b'\xebr\x17D*t\xae\xd4\xe3S\xb6\xe2\xebP1\x8b'
7576

7677

77-
.. function:: token_hex([nbytes=None])
78+
.. function:: token_hex(nbytes=None)
7879

7980
Return a random text string, in hexadecimal. The string has *nbytes*
80-
random bytes, each byte converted to two hex digits. If *nbytes* is
81-
``None`` or not supplied, a reasonable default is used.
81+
random bytes, each byte converted to two hex digits.
82+
83+
If *nbytes* is not specified or ``None``, :const:`DEFAULT_ENTROPY`
84+
is used instead.
8285

8386
.. doctest::
8487

85-
>>> token_hex(16) #doctest:+SKIP
88+
>>> token_hex(16) # doctest: +SKIP
8689
'f9bf78b9a18ce6d46a0cd2b0b86df9da'
8790

88-
.. function:: token_urlsafe([nbytes=None])
91+
.. function:: token_urlsafe(nbytes=None)
8992

9093
Return a random URL-safe text string, containing *nbytes* random
9194
bytes. The text is Base64 encoded, so on average each byte results
92-
in approximately 1.3 characters. If *nbytes* is ``None`` or not
93-
supplied, a reasonable default is used.
95+
in approximately 1.3 characters.
96+
97+
If *nbytes* is not specified or ``None``, :const:`DEFAULT_ENTROPY`
98+
is used instead.
9499

95100
.. doctest::
96101

97-
>>> token_urlsafe(16) #doctest:+SKIP
102+
>>> token_urlsafe(16) # doctest: +SKIP
98103
'Drmhze6EPcv0fN_81Bj-nA'
99104

100105

@@ -115,11 +120,13 @@ argument to the various ``token_*`` functions. That argument is taken
115120
as the number of bytes of randomness to use.
116121

117122
Otherwise, if no argument is provided, or if the argument is ``None``,
118-
the ``token_*`` functions will use a reasonable default instead.
123+
the ``token_*`` functions uses :const:`DEFAULT_ENTROPY` instead.
119124

120-
.. note::
125+
.. data:: DEFAULT_ENTROPY
126+
127+
Default number of bytes of randomness used by the ``token_*`` functions.
121128

122-
That default is subject to change at any time, including during
129+
The exact value is subject to change at any time, including during
123130
maintenance releases.
124131

125132

0 commit comments

Comments
 (0)