MCPcopy Index your code
hub / github.com/python/mypy / clean_up

Function clean_up

mypy/test/helpers.py:272–295  ·  view source on GitHub ↗

Remove common directory prefix from all strings in a. This uses a naive string replace; it seems to work well enough. Also remove trailing carriage returns.

(a: list[str])

Source from the content-addressed store, hash-verified

270
271
272def clean_up(a: list[str]) -> list[str]:
273 """Remove common directory prefix from all strings in a.
274
275 This uses a naive string replace; it seems to work well enough. Also
276 remove trailing carriage returns.
277 """
278 res = []
279 pwd = os.getcwd()
280 driver = pwd + "/driver.py"
281 for s in a:
282 prefix = os.sep
283 ss = s
284 for p in prefix, prefix.replace(os.sep, "/"):
285 if p != "/" and p != "//" and p != "\\" and p != "\\\\":
286 ss = ss.replace(p, "")
287 # Replace memory address with zeros
288 if "at 0x" in ss:
289 ss = re.sub(r"(at 0x)\w+>", r"\g<1>000000000000>", ss)
290 # Ignore spaces at end of line.
291 ss = re.sub(" +$", "", ss)
292 # Remove pwd from driver.py's path
293 ss = ss.replace(driver, "driver.py")
294 res.append(re.sub("\\r$", "", ss))
295 return res
296
297
298@contextlib.contextmanager

Callers 1

Calls 2

replaceMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…