MCPcopy Index your code
hub / github.com/idank/explainshell / postprocess

Function postprocess

explainshell/extraction/postprocess.py:243–285  ·  view source on GitHub ↗

Run selected post-processing steps. steps=None means all. Otherwise a subset like ["sanitize", "dedup", "strip_blanks", "drop_empty", "sanity_check_spans"].

(
    options: list[Option],
    steps: list[str] | None = None,
)

Source from the content-addressed store, hash-verified

241
242
243def postprocess(
244 options: list[Option],
245 steps: list[str] | None = None,
246) -> tuple[list[Option], PostProcessStats]:
247 """Run selected post-processing steps.
248
249 steps=None means all. Otherwise a subset like
250 ["sanitize", "dedup", "strip_blanks", "drop_empty", "sanity_check_spans"].
251 """
252 all_steps = {
253 "sanitize",
254 "dedup",
255 "strip_blanks",
256 "drop_empty",
257 "sanity_check_spans",
258 }
259 active = set(steps) if steps is not None else all_steps
260 stats = PostProcessStats()
261
262 if "sanitize" in active:
263 options = [sanitize_option(opt) for opt in options]
264
265 if "strip_blanks" in active:
266 new_opts = []
267 for opt in options:
268 stripped = strip_trailing_blanks(opt)
269 if stripped is not opt:
270 stats.blank_description_stripped += 1
271 new_opts.append(stripped)
272 options = new_opts
273
274 if "dedup" in active:
275 options, removed = dedup_options(options)
276 stats.deduped_options = removed
277
278 if "drop_empty" in active:
279 options, removed = drop_empty(options)
280 stats.dropped_empty = removed
281
282 if "sanity_check_spans" in active:
283 sanity_check_line_spans(options)
284
285 return options, stats

Callers 1

_finalizeMethod · 0.90

Calls 6

PostProcessStatsClass · 0.85
sanitize_optionFunction · 0.85
strip_trailing_blanksFunction · 0.85
drop_emptyFunction · 0.85
sanity_check_line_spansFunction · 0.85
dedup_optionsFunction · 0.70

Tested by

no test coverage detected