summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.rst4
-rw-r--r--coverage/misc.py16
-rw-r--r--tests/test_misc.py2
3 files changed, 13 insertions, 9 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 8841d944..850c30ec 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -46,9 +46,13 @@ Unreleased
- TOML parsing now uses the `tomli`_ library.
+- Use a modern hash algorithm when fingerprinting to speed HTML reports
+ (`issue 1189`_).
+
.. _Django coverage plugin: https://pypi.org/project/django-coverage-plugin/
.. _issue 1150: https://github.com/nedbat/coveragepy/issues/1150
.. _issue 1168: https://github.com/nedbat/coveragepy/issues/1168
+.. _issue 1189: https://github.com/nedbat/coveragepy/issues/1189
.. _tomli: https://pypi.org/project/tomli/
diff --git a/coverage/misc.py b/coverage/misc.py
index db2c3b75..108cf078 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -198,21 +198,21 @@ def filename_suffix(suffix):
class Hasher:
- """Hashes Python data into md5."""
+ """Hashes Python data for fingerprinting."""
def __init__(self):
- self.md5 = hashlib.md5()
+ self.hash = hashlib.new("sha3_256")
def update(self, v):
"""Add `v` to the hash, recursively if needed."""
- self.md5.update(str(type(v)).encode("utf8"))
+ self.hash.update(str(type(v)).encode("utf8"))
if isinstance(v, str):
- self.md5.update(v.encode('utf8'))
+ self.hash.update(v.encode('utf8'))
elif isinstance(v, bytes):
- self.md5.update(v)
+ self.hash.update(v)
elif v is None:
pass
elif isinstance(v, (int, float)):
- self.md5.update(str(v).encode("utf8"))
+ self.hash.update(str(v).encode("utf8"))
elif isinstance(v, (tuple, list)):
for e in v:
self.update(e)
@@ -230,11 +230,11 @@ class Hasher:
continue
self.update(k)
self.update(a)
- self.md5.update(b'.')
+ self.hash.update(b'.')
def hexdigest(self):
"""Retrieve the hex digest of the hash."""
- return self.md5.hexdigest()
+ return self.hash.hexdigest()
def _needs_to_implement(that, func_name):
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 95ca977d..3858c4f8 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -14,7 +14,7 @@ from tests.coveragetest import CoverageTest
class HasherTest(CoverageTest):
- """Test our wrapper of md5 hashing."""
+ """Test our wrapper of fingerprint hashing."""
run_in_temp_dir = False