[core] Enable ruff PTH (flake8-use-pathlib) lint family (#16661)

This commit is contained in:
J. Nick Koston
2026-05-26 05:14:42 +00:00
committed by GitHub
parent ae814cff5c
commit ae74920b81
54 changed files with 162 additions and 155 deletions
+3 -2
View File
@@ -2,6 +2,7 @@
import argparse
from dataclasses import dataclass
from pathlib import Path
import re
import sys
@@ -39,12 +40,12 @@ class Version:
def sub(path, pattern, repl, expected_count=1):
with open(path, encoding="utf-8") as fh:
with Path(path).open(encoding="utf-8") as fh:
content = fh.read()
content, count = re.subn(pattern, repl, content, flags=re.MULTILINE)
if expected_count is not None:
assert count == expected_count, f"Pattern {pattern} replacement failed!"
with open(path, "w", encoding="utf-8") as fh:
with Path(path).open("w", encoding="utf-8") as fh:
fh.write(content)