statprof: ensure files with binary I/O are opened in binary mode
These appear to have been existing bugs, so maybe this should go on stable.
OTOH, PyCharm is flagging 8 other things in this file, claiming symbols and/or
imports don't exist. I haven't dug into that, but suspect that this module
isn't used much, based on the bugs fixed here and no previous complaints.
These were previously hidden by the `pycompat.open()` import, because that is
typed as returning `Any` instead of `BinaryIO`. (I didn't look up the reason
for that, but do recall there was one.)
--- a/mercurial/statprof.py Wed Dec 04 22:02:36 2024 -0500
+++ b/mercurial/statprof.py Wed Dec 04 22:07:56 2024 -0500
@@ -384,7 +384,7 @@
def save_data(path):
- with open(path, 'w+') as file:
+ with open(path, 'w+b') as file:
file.write(b"%f %f\n" % state.accumulated_time)
for sample in state.samples:
time = sample.time
@@ -830,7 +830,7 @@
fd, path = pycompat.mkstemp()
- with open(path, "w+") as file:
+ with open(path, "w+b") as file:
for line, count in lines.items():
file.write(b"%s %d\n" % (line, count))