diff --git a/CHANGES.rst b/CHANGES.rst
index 6b12c8fc8..51d6bead2 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -20,9 +20,10 @@ development at the same time, such as 4.5.x and 5.0.
Unreleased
----------
-- Performance: HTML reports with context information are now much more compact,
- with file sizes typically as small as one-third the previous size. This
- closes `issue 1584`_ thanks to `Oleh Krehel `_.
+- Performance: HTML reports with context information are now much more compact.
+ File sizes are typically as small as one-third the previous size, but can be
+ dramatically smaller. This closes `issue 1584`_ thanks to `Oleh Krehel
+ `_.
.. _issue 1584: https://github.com/nedbat/coveragepy/issues/1584
.. _pull 1587: https://github.com/nedbat/coveragepy/pull/1587
diff --git a/coverage/html.py b/coverage/html.py
index 23fba3f0a..b3f37f760 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -5,12 +5,12 @@
from __future__ import annotations
+import collections
import datetime
import json
import os
import re
import shutil
-from collections import Counter
from dataclasses import dataclass
from typing import Any, Dict, Iterable, List, Optional, Tuple, TYPE_CHECKING, cast
@@ -370,7 +370,7 @@ def write_html_file(self, ftr: FileToReport, prev_html: str, next_html: str) ->
# Write the HTML page for this file.
file_data = self.datagen.data_for_file(ftr.fr, ftr.analysis)
- contexts = Counter(c for cline in file_data.lines for c in cline.contexts)
+ contexts = collections.Counter(c for cline in file_data.lines for c in cline.contexts)
context_codes = {y: i for (i, y) in enumerate(x[0] for x in contexts.most_common())}
contexts_json = json.dumps({v: k for (k, v) in context_codes.items()}, indent=2)
@@ -386,9 +386,9 @@ def write_html_file(self, ftr: FileToReport, prev_html: str, next_html: str) ->
f'{tok_html}'
)
ldata.html = ''.join(html_parts)
-
ldata.context_str = ",".join(
- str(context_codes[c_context]) for c_context in ldata.context_list)
+ str(context_codes[c_context]) for c_context in ldata.context_list
+ )
if ldata.short_annotations:
# 202F is NARROW NO-BREAK SPACE.
@@ -423,9 +423,9 @@ def write_html_file(self, ftr: FileToReport, prev_html: str, next_html: str) ->
ldata.css_class = ' '.join(css_classes) or "pln"
if context_codes:
- file_data.__dict__["contexts_json"] = contexts_json
+ file_data.contexts_json = contexts_json
else:
- file_data.__dict__["contexts_json"] = None
+ file_data.contexts_json = None
html_path = os.path.join(self.directory, ftr.html_filename)
html = self.source_tmpl.render({
**file_data.__dict__,
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js
index 8b7fb96f1..1cd2b5d4c 100644
--- a/coverage/htmlfiles/coverage_html.js
+++ b/coverage/htmlfiles/coverage_html.js
@@ -604,8 +604,7 @@ coverage.showContexts = function (e) {
span = e.target.nextElementSibling.nextElementSibling;
span_text = span.textContent;
- if (/^[0-9,]+$/.test(span_text))
- {
+ if (/^[0-9,]+$/.test(span_text)) {
span.textContent = "";
span_text.split(",").forEach(function(s) {
ctx = contexts[s];
diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html
index 1921e1c20..bc8fa697d 100644
--- a/coverage/htmlfiles/pyfile.html
+++ b/coverage/htmlfiles/pyfile.html
@@ -14,7 +14,7 @@
{% if contexts_json %}
{% endif %}
@@ -125,9 +125,7 @@
{# Things that should appear below the line. #}
{% if line.context_str %}
-
- {{ line.context_str }}
-
+ {{ line.context_str }}
{% endif %}