remove_unneeded_type_ignores.py 693 B

123456789101112131415161718192021222324252627
  1. from __future__ import annotations
  2. import subprocess
  3. import sys
  4. def main() -> int:
  5. cmd = (sys.executable, "-m", "tools.mypy_helpers.mypy_without_ignores", *sys.argv[1:])
  6. out = subprocess.run(cmd, stdout=subprocess.PIPE)
  7. for line in out.stdout.decode().splitlines():
  8. if line.endswith("[unused-ignore]"):
  9. fname, n, *_ = line.split(":")
  10. subprocess.check_call(
  11. (
  12. "sed",
  13. "-i",
  14. "-r",
  15. rf"{n}s/# type: ?ignore[^#]*(#|$)/\1/g",
  16. fname,
  17. )
  18. )
  19. return 0
  20. if __name__ == "__main__":
  21. raise SystemExit(main())