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

Function fix_native_line_number

mypyc/test/test_run.py:506–530  ·  view source on GitHub ↗

Update code locations in test case output to point to the .test file. The description of the test case is written to native.py, and line numbers in test case output often are relative to native.py. This translates the line numbers to be relative to the .test file that contains the test

(message: str, fnam: str, delta: int)

Source from the content-addressed store, hash-verified

504
505
506def fix_native_line_number(message: str, fnam: str, delta: int) -> str:
507 """Update code locations in test case output to point to the .test file.
508
509 The description of the test case is written to native.py, and line numbers
510 in test case output often are relative to native.py. This translates the
511 line numbers to be relative to the .test file that contains the test case
512 description, and also updates the file name to the .test file name.
513
514 Args:
515 message: message to update
516 fnam: path of the .test file
517 delta: line number of the beginning of the test case in the .test file
518
519 Returns updated message (or original message if we couldn't find anything).
520 """
521 fnam = os.path.basename(fnam)
522 message = re.sub(
523 r"native\.py:([0-9]+):", lambda m: "%s:%d:" % (fnam, int(m.group(1)) + delta), message
524 )
525 message = re.sub(
526 r'"native.py", line ([0-9]+),',
527 lambda m: '"%s", line %d,' % (fnam, int(m.group(1)) + delta),
528 message,
529 )
530 return message
531
532
533def copy_output_files(target_dir: str) -> None:

Callers 1

run_case_stepMethod · 0.85

Calls 2

intClass · 0.85
groupMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…