https://github.com/python/cpython/commit/381144f0431fc27e8b49d72d40434c8666a92ff5
commit: 381144f0431fc27e8b49d72d40434c8666a92ff5
branch: 3.14
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: AA-Turner <9087854+aa-tur...@users.noreply.github.com>
date: 2025-05-28T16:37:57Z
summary:

[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 b265a7ddeb12b2040d80b471d447ce4c3ff4bb95)

Co-authored-by: Adam Turner <9087854+aa-tur...@users.noreply.github.com>

files:
M Doc/tools/extensions/audit_events.py

diff --git a/Doc/tools/extensions/audit_events.py 
b/Doc/tools/extensions/audit_events.py
index 23d82c0f4414bf..385a58b2145446 100644
--- a/Doc/tools/extensions/audit_events.py
+++ b/Doc/tools/extensions/audit_events.py
@@ -13,7 +13,7 @@
 from sphinx.util.docutils import SphinxDirective
 
 if TYPE_CHECKING:
-    from collections.abc import Iterator
+    from collections.abc import Iterator, Set
 
     from sphinx.application import Sphinx
     from sphinx.builders import Builder
@@ -33,7 +33,7 @@
 class AuditEvents:
     def __init__(self) -> None:
         self.events: dict[str, list[str]] = {}
-        self.sources: dict[str, list[tuple[str, str]]] = {}
+        self.sources: dict[str, set[tuple[str, str]]] = {}
 
     def __iter__(self) -> Iterator[tuple[str, list[str], tuple[str, str]]]:
         for name, args in self.events.items():
@@ -47,7 +47,7 @@ def add_event(
             self._check_args_match(name, args)
         else:
             self.events[name] = args
-        self.sources.setdefault(name, []).append(source)
+        self.sources.setdefault(name, set()).add(source)
 
     def _check_args_match(self, name: str, args: list[str]) -> None:
         current_args = self.events[name]
@@ -69,11 +69,11 @@ def _check_args_match(self, name: str, args: list[str]) -> 
None:
             return
 
     def id_for(self, name) -> str:
-        source_count = len(self.sources.get(name, ()))
+        source_count = len(self.sources.get(name, set()))
         name_clean = re.sub(r"\W", "_", name)
         return f"audit_event_{name_clean}_{source_count}"
 
-    def rows(self) -> Iterator[tuple[str, list[str], list[tuple[str, str]]]]:
+    def rows(self) -> Iterator[tuple[str, list[str], Set[tuple[str, str]]]]:
         for name in sorted(self.events.keys()):
             yield name, self.events[name], self.sources[name]
 
@@ -218,7 +218,7 @@ def _make_row(
         docname: str,
         name: str,
         args: list[str],
-        sources: list[tuple[str, str]],
+        sources: Set[tuple[str, str]],
     ) -> nodes.row:
         row = nodes.row()
         name_node = nodes.paragraph("", nodes.Text(name))
@@ -233,7 +233,7 @@ def _make_row(
         row += nodes.entry("", args_node)
 
         backlinks_node = nodes.paragraph()
-        backlinks = enumerate(sorted(set(sources)), start=1)
+        backlinks = enumerate(sorted(sources), start=1)
         for i, (doc, label) in backlinks:
             if isinstance(label, str):
                 ref = nodes.reference("", f"[{i}]", internal=True)
@@ -258,7 +258,7 @@ def setup(app: Sphinx):
     app.connect("env-purge-doc", audit_events_purge)
     app.connect("env-merge-info", audit_events_merge)
     return {
-        "version": "1.0",
+        "version": "2.0",
         "parallel_read_safe": True,
         "parallel_write_safe": True,
     }

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to