typing: suppress bogus pytype errors in `mercurial/wireprotov1peer.py`
authorMatt Harbison <matt_harbison@yahoo.com>
Fri, 25 Oct 2024 23:45:05 -0400
changeset 52130 8b791764fc52
parent 52129 ff13068e9b1c
child 52131 2dce4c01cec1
typing: suppress bogus pytype errors in `mercurial/wireprotov1peer.py` Fixes: File "/mnt/c/Users/Matt/hg/mercurial/wireprotov1peer.py", line 100, in result: No attribute '_peerexecutor' on unsentfuture [attribute-error] File "/mnt/c/Users/Matt/hg/mercurial/wireprotov1peer.py", line 278, in close: No attribute 'shutdown' on None [attribute-error] Called from (traceback): line 123, in __exit__ File "/mnt/c/Users/Matt/hg/mercurial/wireprotov1peer.py", line 278, in close: No attribute 'shutdown' on None [attribute-error] In Optional[concurrent.futures.thread.ThreadPoolExecutor] We drop the zope decorator on `peerexecutor`, because otherwise it triggers this error: File "/tmp/mercurial-ci/mercurial/wireprotov1peer.py", line 111, in <module>: Invalid type annotation [invalid-annotation] Must be constant Not sure why, because the decorated classes usually get typed as `Any`, which would also be fine here.
mercurial/wireprotov1peer.py
--- a/mercurial/wireprotov1peer.py	Fri Oct 25 23:09:10 2024 -0400
+++ b/mercurial/wireprotov1peer.py	Fri Oct 25 23:45:05 2024 -0400
@@ -93,6 +93,8 @@
     call ``sendcommands()``.
     """
 
+    _peerexecutor: "peerexecutor"
+
     def result(self, timeout=None):
         if self.done():
             return futures.Future.result(self, timeout)
@@ -105,7 +107,7 @@
         return self.result(timeout)
 
 
-@interfaceutil.implementer(repository.ipeercommandexecutor)
+# @interfaceutil.implementer(repository.ipeercommandexecutor)
 class peerexecutor:
     def __init__(self, peer):
         self._peer = peer
@@ -275,6 +277,9 @@
         try:
             self._responsef.result()
         finally:
+            # Help pytype- this is initialized by self.sendcommands(), called
+            # above.
+            assert self._responseexecutor is not None
             self._responseexecutor.shutdown(wait=True)
             self._responsef = None
             self._responseexecutor = None