Skip to content

Commit 381144f

Browse files
[3.14] GH-134848: Use a set to store AuditEvents.sources (GH-134849) (#134853)
GH-134848: Use a set to store ``AuditEvents.sources`` (GH-134849) (cherry picked from commit b265a7d) Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent 4841201 commit 381144f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Doc/tools/extensions/audit_events.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from sphinx.util.docutils import SphinxDirective
1414

1515
if TYPE_CHECKING:
16-
from collections.abc import Iterator
16+
from collections.abc import Iterator, Set
1717

1818
from sphinx.application import Sphinx
1919
from sphinx.builders import Builder
@@ -33,7 +33,7 @@
3333
class AuditEvents:
3434
def __init__(self) -> None:
3535
self.events: dict[str, list[str]] = {}
36-
self.sources: dict[str, list[tuple[str, str]]] = {}
36+
self.sources: dict[str, set[tuple[str, str]]] = {}
3737

3838
def __iter__(self) -> Iterator[tuple[str, list[str], tuple[str, str]]]:
3939
for name, args in self.events.items():
@@ -47,7 +47,7 @@ def add_event(
4747
self._check_args_match(name, args)
4848
else:
4949
self.events[name] = args
50-
self.sources.setdefault(name, []).append(source)
50+
self.sources.setdefault(name, set()).add(source)
5151

5252
def _check_args_match(self, name: str, args: list[str]) -> None:
5353
current_args = self.events[name]
@@ -69,11 +69,11 @@ def _check_args_match(self, name: str, args: list[str]) -> None:
6969
return
7070

7171
def id_for(self, name) -> str:
72-
source_count = len(self.sources.get(name, ()))
72+
source_count = len(self.sources.get(name, set()))
7373
name_clean = re.sub(r"\W", "_", name)
7474
return f"audit_event_{name_clean}_{source_count}"
7575

76-
def rows(self) -> Iterator[tuple[str, list[str], list[tuple[str, str]]]]:
76+
def rows(self) -> Iterator[tuple[str, list[str], Set[tuple[str, str]]]]:
7777
for name in sorted(self.events.keys()):
7878
yield name, self.events[name], self.sources[name]
7979

@@ -218,7 +218,7 @@ def _make_row(
218218
docname: str,
219219
name: str,
220220
args: list[str],
221-
sources: list[tuple[str, str]],
221+
sources: Set[tuple[str, str]],
222222
) -> nodes.row:
223223
row = nodes.row()
224224
name_node = nodes.paragraph("", nodes.Text(name))
@@ -233,7 +233,7 @@ def _make_row(
233233
row += nodes.entry("", args_node)
234234

235235
backlinks_node = nodes.paragraph()
236-
backlinks = enumerate(sorted(set(sources)), start=1)
236+
backlinks = enumerate(sorted(sources), start=1)
237237
for i, (doc, label) in backlinks:
238238
if isinstance(label, str):
239239
ref = nodes.reference("", f"[{i}]", internal=True)
@@ -258,7 +258,7 @@ def setup(app: Sphinx):
258258
app.connect("env-purge-doc", audit_events_purge)
259259
app.connect("env-merge-info", audit_events_merge)
260260
return {
261-
"version": "1.0",
261+
"version": "2.0",
262262
"parallel_read_safe": True,
263263
"parallel_write_safe": True,
264264
}

0 commit comments

Comments
 (0)