# HG changeset patch # User Matt Harbison # Date 2024-12-06 04:22:40 # Node ID 5ff6fba7c4c5f29331f1da74bb142935016cb8b9 # Parent bde718849153719647431dcf83c27f24c8e3bfaa 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. diff --git a/mercurial/profiling.py b/mercurial/profiling.py --- a/mercurial/profiling.py +++ b/mercurial/profiling.py @@ -341,7 +341,10 @@ class profile: 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'%%')