summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/summarize_stats.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-01-10 13:07:19 (GMT)
committerGitHub <noreply@github.com>2024-01-10 13:07:19 (GMT)
commitb3d2427f2280fa8dae3515036c518d74ba43ebd1 (patch)
treee9fda1fdaf580c57ca6bda8c0d7e7bfc965f91d5 /Tools/scripts/summarize_stats.py
parenta8629816c6c0e6770248a60529fd7c9ba08aad55 (diff)
downloadcpython-b3d2427f2280fa8dae3515036c518d74ba43ebd1.zip
cpython-b3d2427f2280fa8dae3515036c518d74ba43ebd1.tar.gz
cpython-b3d2427f2280fa8dae3515036c518d74ba43ebd1.tar.bz2
gh-58032: Do not use argparse.FileType in module CLIs and scripts (GH-113649)
Open and close files manually. It prevents from leaking files, preliminary creation of output files, and accidental closing of stdin and stdout.
Diffstat (limited to 'Tools/scripts/summarize_stats.py')
-rw-r--r--Tools/scripts/summarize_stats.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py
index 80a1280..df8a7fd 100644
--- a/Tools/scripts/summarize_stats.py
+++ b/Tools/scripts/summarize_stats.py
@@ -1154,12 +1154,13 @@ def output_markdown(
print("Stats gathered on:", date.today(), file=out)
-def output_stats(inputs: list[Path], json_output=TextIO | None):
+def output_stats(inputs: list[Path], json_output=str | None):
match len(inputs):
case 1:
data = load_raw_data(Path(inputs[0]))
if json_output is not None:
- save_raw_data(data, json_output) # type: ignore
+ with open(json_output, 'w', encoding='utf-8') as f:
+ save_raw_data(data, f) # type: ignore
stats = Stats(data)
output_markdown(sys.stdout, LAYOUT, stats)
case 2:
@@ -1195,7 +1196,6 @@ def main():
parser.add_argument(
"--json-output",
nargs="?",
- type=argparse.FileType("w"),
help="Output complete raw results to the given JSON file.",
)