From f66f5715c12ed1e4957a730e59310d760b9e8822 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Tue, 26 May 2026 16:33:41 +0900 Subject: [PATCH] Use itertools.count for MermaidRenderer node IDs Per review feedback, the small next_id() closure that combined a 'nonlocal node_counter' assignment with an f-string formatter is more naturally expressed as itertools.count. The counter generator yields the integer sequence starting at 1 and the call site formats it as 'n' on the spot, so the behaviour is unchanged: per-render, strictly-increasing, plugin-agnostic Mermaid node identifiers. --- volatility3/cli/text_renderer.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/volatility3/cli/text_renderer.py b/volatility3/cli/text_renderer.py index 494606861..8c4a27024 100644 --- a/volatility3/cli/text_renderer.py +++ b/volatility3/cli/text_renderer.py @@ -3,6 +3,7 @@ # import csv import datetime +import itertools import json import logging import random @@ -708,12 +709,7 @@ class MermaidRenderer(CLIRenderer): # PID) because (a) PID is not guaranteed unique across a TreeGrid, # (b) it is plugin-specific, and (c) Mermaid IDs must avoid # characters like parentheses that may appear in column data. - node_counter = 0 - - def next_id() -> str: - nonlocal node_counter - node_counter += 1 - return f"n{node_counter}" + node_ids = itertools.count(1) parent_stack: List[str] = [] prev_depth = 0 @@ -721,7 +717,7 @@ class MermaidRenderer(CLIRenderer): lines: List[str] = ["graph TD"] for depth, label in rows: - node_id = next_id() + node_id = f"n{next(node_ids)}" if prev_id is not None: if depth > prev_depth: # Descended one or more levels. Push prev_id once per