Mercurial > public > mercurial-scm > hg-stable
diff mercurial/profiling.py @ 52431:5ff6fba7c4c5
profiling: add an assertion to help pytype
Pytype 2023.11.21 with Python 3.10.11 (correctly) flagged `self._fp` as possibly
not having a `getvalue()` method, likely since 6a8edf9f0a6d:
File "/mnt/c/Users/Matt/hg/mercurial/profiling.py", line 344, in __exit__:
No attribute 'getvalue' on BinaryIO [attribute-error]
In Union[Any, BinaryIO, io.BytesIO]
It appears this was flagged in CI too, but the test was marked as a success
anyway, so it wasn't noticed. We'll fix that on stable and then merge on top of
this.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 05 Dec 2024 23:22:40 -0500 |
parents | 6a8edf9f0a6d |
children |
line wrap: on
line diff
--- a/mercurial/profiling.py Tue Dec 03 09:44:57 2024 -0500 +++ b/mercurial/profiling.py Thu Dec 05 23:22:40 2024 -0500 @@ -341,7 +341,10 @@ exception_type, exception_value, traceback ) if self._output == b'blackbox': - val = b'Profile:\n%s' % self._fp.getvalue() + fp = self._fp + # Help pytype: blackbox output uses io.BytesIO instead of a file + assert isinstance(fp, util.stringio) + val = b'Profile:\n%s' % fp.getvalue() # ui.log treats the input as a format string, # so we need to escape any % signs. val = val.replace(b'%', b'%%')