mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-03-15 19:18:55 +08:00
All scripts/tests: always specify file encoding in calls to open() (#8882)
This commit is contained in:
@@ -70,7 +70,7 @@ def create_metadata(stub_dir: str, version: str) -> None:
|
||||
if os.path.exists(filename):
|
||||
return
|
||||
print(f"Writing {filename}")
|
||||
with open(filename, "w") as file:
|
||||
with open(filename, "w", encoding="UTF-8") as file:
|
||||
file.write(
|
||||
f"""\
|
||||
version = "{version}.*"
|
||||
@@ -83,7 +83,7 @@ ignore_missing_stub = false
|
||||
|
||||
def add_pyright_exclusion(stub_dir: str) -> None:
|
||||
"""Exclude stub_dir from strict pyright checks."""
|
||||
with open(PYRIGHT_CONFIG) as f:
|
||||
with open(PYRIGHT_CONFIG, encoding="UTF-8") as f:
|
||||
lines = f.readlines()
|
||||
i = 0
|
||||
while i < len(lines) and not lines[i].strip().startswith('"exclude": ['):
|
||||
@@ -105,7 +105,7 @@ def add_pyright_exclusion(stub_dir: str) -> None:
|
||||
lines[i] = lines[i].rstrip() + ",\n"
|
||||
lines.insert(i + 1, line_to_add + "\n")
|
||||
print(f"Updating {PYRIGHT_CONFIG}")
|
||||
with open(PYRIGHT_CONFIG, "w") as f:
|
||||
with open(PYRIGHT_CONFIG, "w", encoding="UTF-8") as f:
|
||||
f.writelines(lines)
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ def _parse_jsonc(json_text: str) -> str:
|
||||
|
||||
|
||||
def _get_strict_params(stub_path: str) -> list[str]:
|
||||
with open(_STRICTER_CONFIG_FILE) as file:
|
||||
with open(_STRICTER_CONFIG_FILE, encoding="UTF-8") as file:
|
||||
data = json.loads(_parse_jsonc(file.read()))
|
||||
if stub_path in data["exclude"]:
|
||||
return []
|
||||
|
||||
@@ -610,7 +610,7 @@ async def suggest_typeshed_update(update: Update, session: aiohttp.ClientSession
|
||||
with open(update.stub_path / "METADATA.toml", "rb") as f:
|
||||
meta = tomlkit.load(f)
|
||||
meta["version"] = update.new_version_spec
|
||||
with open(update.stub_path / "METADATA.toml", "w") as f:
|
||||
with open(update.stub_path / "METADATA.toml", "w", encoding="UTF-8") as f:
|
||||
tomlkit.dump(meta, f)
|
||||
body = get_update_pr_body(update, meta)
|
||||
subprocess.check_call(["git", "commit", "--all", "-m", f"{title}\n\n{body}"])
|
||||
@@ -638,7 +638,7 @@ async def suggest_typeshed_obsolete(obsolete: Obsolete, session: aiohttp.ClientS
|
||||
obs_string = tomlkit.string(obsolete.obsolete_since_version)
|
||||
obs_string.comment(f"Released on {obsolete.obsolete_since_date.date().isoformat()}")
|
||||
meta["obsolete_since"] = obs_string
|
||||
with open(obsolete.stub_path / "METADATA.toml", "w") as f:
|
||||
with open(obsolete.stub_path / "METADATA.toml", "w", encoding="UTF-8") as f:
|
||||
tomlkit.dump(meta, f)
|
||||
body = "\n".join(f"{k}: {v}" for k, v in obsolete.links.items())
|
||||
subprocess.check_call(["git", "commit", "--all", "-m", f"{title}\n\n{body}"])
|
||||
|
||||
Reference in New Issue
Block a user