Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2aa6f4

Browse files
committed
Issue 18532: Added tests and documentation to formally specify the .name attribute on hashlib objects.
1 parent 21e9ac7 commit b2aa6f4

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

Doc/library/hashlib.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ returned by the constructors:
124124

125125
The internal block size of the hash algorithm in bytes.
126126

127+
A hash object has the following attributes:
128+
129+
.. attribute:: hash.name
130+
131+
The canonical name of this hash, always lowercase and always suitable as a
132+
parameter to :func:`new` to create another hash of this type.
133+
134+
.. versionchanged:: 3.4
135+
The name attribute has been present in CPython since its inception, but
136+
until Python 3.4 was not formally specified, so may not exist on some
137+
platforms.
138+
127139
A hash object has the following methods:
128140

129141

Lib/test/test_hashlib.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ def test_hexdigest(self):
154154
assert isinstance(h.digest(), bytes), name
155155
self.assertEqual(hexstr(h.digest()), h.hexdigest())
156156

157+
def test_name_attribute(self):
158+
for cons in self.hash_constructors:
159+
h = cons()
160+
assert isinstance(h.name, str), "No name attribute"
161+
assert h.name in self.supported_hash_names
157162

158163
def test_large_update(self):
159164
aas = b'a' * 128

0 commit comments

Comments
 (0)