MCPcopy
hub / github.com/rspeer/python-ftfy / _try_fix

Function _try_fix

ftfy/__init__.py:270–287  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

268
269
270def _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
290def fix_text(text: str, config: TextFixerConfig | None = None, **kwargs: Any) -> str:

Callers 1

fix_and_explainFunction · 0.85

Calls 1

ExplanationStepClass · 0.85

Tested by

no test coverage detected