55from __future__ import annotations
66
77import re
8- from collections import defaultdict
98from contextlib import nullcontext
109from dataclasses import dataclass
11- from typing import TYPE_CHECKING , Any , Literal , TypedDict , cast
10+ from typing import TYPE_CHECKING , Any , Literal , TypedDict
1211
1312from django .http import Http404
1413from django .utils .html import format_html , format_html_join
@@ -447,7 +446,7 @@ def format_result(self, result: MissingExtraDict) -> Iterable[StrOrPromise]:
447446 yield self .get_errors_text (set (errors ))
448447
449448
450- class PluralResultDescriptionMixin :
449+ class PluralResultDescriptionMixin ( TargetCheck ) :
451450 """
452451 Build check descriptions by merging MissingExtraDict results across plurals.
453452
@@ -460,16 +459,21 @@ def get_description(self, check_obj: Check) -> StrOrPromise:
460459 unit = check_obj .unit
461460
462461 errors : list [StrOrPromise ] = []
463- results : MissingExtraDict = cast ("MissingExtraDict" , defaultdict (list ))
464462
465463 # Merge plurals
464+ results : MissingExtraDict = {}
466465 for result in self .check_target_generator (
467466 unit .get_source_plurals (), unit .get_target_plurals (), unit
468467 ):
469- if isinstance (result , dict ):
470- for key , value in result .items ():
471- results [key ].extend (value )
472- if results :
468+ if not isinstance (result , dict ):
469+ continue
470+ if missing := result .get ("missing" ):
471+ results .setdefault ("missing" , []).extend (missing )
472+ if extra := result .get ("extra" ):
473+ results .setdefault ("extra" , []).extend (extra )
474+ if result_errors := result .get ("errors" ):
475+ results .setdefault ("errors" , []).extend (result_errors )
476+ if any (results .values ()):
473477 errors .extend (self .format_result (results ))
474478 if errors :
475479 return format_html_join (
0 commit comments