Skip to content

GH-134848: Use a set to store AuditEvents.sources #134849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Doc/tools/extensions/audit_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand All @@ -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]
Expand All @@ -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]

Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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,
}
Loading