diff mercurial/statprof.py @ 52377:ef83646d5f7d

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.)
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 04 Dec 2024 22:07:56 -0500
parents 9b43246e710e
children f4d1f0713b49
line wrap: on
line diff
--- 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))