Coverage for app/venv/lib/python3.14/site-packages/weblate/trans/autofixes/__init__.py: 53%

24 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 07:15 +0000

1# Copyright © Michal Čihař <michal@weblate.org> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4 

5""" 

6Import all the autofixes defined in settings. 

7 

8Note, unlike checks, using a sortable data object so fixes are applied in desired order. 

9""" 

10 

11from __future__ import annotations 

12 

13from typing import TYPE_CHECKING 

14 

15from weblate.utils.classloader import ClassLoader 

16 

17from .base import AutoFix 

18 

19if TYPE_CHECKING: 19 ↛ 20line 19 didn't jump to line 20 because the condition on line 19 was never true

20 from collections.abc import Iterator 

21 

22 from weblate.trans.models.unit import Unit 

23 

24 

25class AutofixLoader(ClassLoader[AutoFix]): 

26 def __init__(self) -> None: 

27 super().__init__("AUTOFIX_LIST", base_class=AutoFix) 

28 

29 def get_ignore_strings(self) -> Iterator[str]: 

30 for fix in self.values(): 

31 for check in fix.get_related_checks(): 

32 yield check.ignore_string 

33 

34 

35AUTOFIXES = AutofixLoader() 

36 

37 

38def fix_target(target: list[str], unit: Unit) -> tuple[list[str], list[str]]: 

39 """Apply each autofix to the target translation.""" 

40 if target == []: 

41 return target, [] 

42 fixups = [] 

43 for fix in AUTOFIXES.values(): 

44 target, fixed = fix.fix_target(target, unit) 

45 if fixed: 

46 fixups.append(fix.name) 

47 

48 return target, fixups