typing: suppress bogus pytype errors in `mercurial/wireprotoframing.py`
authorMatt Harbison <matt_harbison@yahoo.com>
Fri, 25 Oct 2024 23:07:34 -0400
changeset 52129 0c260e7158e0
parent 52128 fd200f5bcaea
child 52130 ff13068e9b1c
typing: suppress bogus pytype errors in `mercurial/wireprotoframing.py` This fixes: File "/mnt/c/Users/Matt/hg/mercurial/wireprotoframing.py", line 480, in createalternatelocationresponseframe: unsupported operand type(s) for item assignment: bytes [unsupported-operands] No attribute '__setitem__' on bytes File "/mnt/c/Users/Matt/hg/mercurial/wireprotoframing.py", line 510, in createcommanderrorresponse: unsupported operand type(s) for item assignment: bytes [unsupported-operands] No attribute '__setitem__' on bytes File "/mnt/c/Users/Matt/hg/mercurial/wireprotoframing.py", line 776, in __init__: Can't find module 'mercurial.zstd'. [import-error] File "/mnt/c/Users/Matt/hg/mercurial/wireprotoframing.py", line 804, in __init__: Can't find module 'mercurial.zstd'. [import-error] File "/mnt/c/Users/Matt/hg/mercurial/wireprotoframing.py", line 834, in populatestreamencoders: Can't find module 'mercurial.zstd'. [import-error] Using `TypedDict` is tempting here to fix the first two, but requires str keys. The code doing the importing doesn't call the code at the other three locations if the `mercurial.zstd` module fails to import in a place that handles the ImportError.
mercurial/wireprotoframing.py
--- a/mercurial/wireprotoframing.py	Thu Oct 24 22:47:31 2024 -0400
+++ b/mercurial/wireprotoframing.py	Fri Oct 25 23:07:34 2024 -0400
@@ -477,7 +477,9 @@
     ):
         value = getattr(location, a)
         if value is not None:
+            # pytype: disable=unsupported-operands
             data[b'location'][pycompat.bytestr(a)] = value
+            # pytype: enable=unsupported-operands
 
     payload = b''.join(cborutil.streamencode(data))
 
@@ -507,7 +509,7 @@
     }
 
     if args:
-        m[b'error'][b'args'] = args
+        m[b'error'][b'args'] = args  # pytype: disable=unsupported-operands
 
     overall = b''.join(cborutil.streamencode(m))
 
@@ -773,7 +775,7 @@
 
 class zstdbaseencoder:
     def __init__(self, level):
-        from . import zstd
+        from . import zstd  # pytype: disable=import-error
 
         self._zstd = zstd
         cctx = zstd.ZstdCompressor(level=level)
@@ -801,7 +803,7 @@
 
 class zstdbasedecoder:
     def __init__(self, maxwindowsize):
-        from . import zstd
+        from . import zstd  # pytype: disable=import-error
 
         dctx = zstd.ZstdDecompressor(max_window_size=maxwindowsize)
         self._decompressor = dctx.decompressobj()
@@ -831,7 +833,7 @@
         return
 
     try:
-        from . import zstd
+        from . import zstd  # pytype: disable=import-error
 
         zstd.__version__
     except ImportError: