A helper function used across several 'fixer' steps, deciding whether to apply the fix and whether to record the fix in `steps`.
(
fixer_name: str,
text: str,
config: TextFixerConfig,
steps: list[ExplanationStep] | None,
)
| 268 | |
| 269 | |
| 270 | def _try_fix( |
| 271 | fixer_name: str, |
| 272 | text: str, |
| 273 | config: TextFixerConfig, |
| 274 | steps: list[ExplanationStep] | None, |
| 275 | ) -> str: |
| 276 | """ |
| 277 | A helper function used across several 'fixer' steps, deciding whether to |
| 278 | apply the fix and whether to record the fix in `steps`. |
| 279 | """ |
| 280 | if getattr(config, fixer_name): |
| 281 | fixer = FIXERS[fixer_name] |
| 282 | fixed = fixer(text) |
| 283 | if steps is not None and fixed != text: |
| 284 | steps.append(ExplanationStep("apply", fixer_name)) |
| 285 | return cast(str, fixed) |
| 286 | |
| 287 | return text |
| 288 | |
| 289 | |
| 290 | def fix_text(text: str, config: TextFixerConfig | None = None, **kwargs: Any) -> str: |
no test coverage detected