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

Function write_and_fudge_mtime

mypy/test/helpers.py:429–447  ·  view source on GitHub ↗
(content: str, target_path: str)

Source from the content-addressed store, hash-verified

427
428
429def write_and_fudge_mtime(content: str, target_path: str) -> None:
430 # In some systems, mtime has a resolution of 1 second which can
431 # cause annoying-to-debug issues when a file has the same size
432 # after a change. We manually set the mtime to circumvent this.
433 # Note that we increment the old file's mtime, which guarantees a
434 # different value, rather than incrementing the mtime after the
435 # copy, which could leave the mtime unchanged if the old file had
436 # a similarly fudged mtime.
437 new_time = None
438 if os.path.isfile(target_path):
439 new_time = os.stat(target_path).st_mtime + 1
440
441 dir = os.path.dirname(target_path)
442 os.makedirs(dir, exist_ok=True)
443 with open(target_path, "w", encoding="utf-8") as target:
444 target.write(content)
445
446 if new_time:
447 os.utime(target_path, times=(new_time, new_time))
448
449
450def perform_file_operations(operations: list[UpdateFile | DeleteFile]) -> None:

Callers 1

perform_file_operationsFunction · 0.85

Calls 2

isfileMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…