From 97f3971e107b7d3776ec7f061929541a67e4cc19 Mon Sep 17 00:00:00 2001 From: jackbrett Date: Fri, 3 Oct 2025 12:29:40 -0500 Subject: [PATCH] Fix thread safety bug in lazy load pattern --- zxcvbn/matching.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zxcvbn/matching.py b/zxcvbn/matching.py index e211ab3..85381e3 100644 --- a/zxcvbn/matching.py +++ b/zxcvbn/matching.py @@ -22,10 +22,9 @@ def get_ranked_dictionaries(): # Do the expensive import here only from zxcvbn.frequency_lists import FREQUENCY_LISTS - # Build the dictionary once - RANKED_DICTIONARIES = {} - for name, lst in FREQUENCY_LISTS.items(): - RANKED_DICTIONARIES[name] = build_ranked_dict(lst) + # Build in local scope before adding to global scope for thread safety + built_dict = {name: build_ranked_dict(lst) for name, lst in FREQUENCY_LISTS.items()} + RANKED_DICTIONARIES = built_dict return RANKED_DICTIONARIES @@ -40,6 +39,7 @@ def wrapper(*args, **kwargs): return func(*args, **kwargs) return wrapper + GRAPHS = { 'qwerty': adjacency_graphs.ADJACENCY_GRAPHS['qwerty'], 'dvorak': adjacency_graphs.ADJACENCY_GRAPHS['dvorak'],