Patchwork D10122: shelve: fix conversion of exceptions to strings flagged by pytype

login
register
mail settings
Submitter phabricator
Date March 7, 2021, 12:45 a.m.
Message ID <differential-rev-PHID-DREV-vdrnvee3rvtv2xgpzdxh-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48438/
State Superseded
Headers show

Comments

phabricator - March 7, 2021, 12:45 a.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I've seen this done several ways and don't know what's correct.  But pytype was
  unhappy about the previous way:
  
    FAILED: /mnt/c/Users/Matt/hg/tests/.pytype/pyi/mercurial/shelve.pyi
    /usr/bin/python3.6 -m pytype.single --imports_info /mnt/c/Users/Matt/hg/tests/.pytype/imports/mercurial.shelve.imports --module-name mercurial.shelve -V 3.6 -o /mnt/c/Users/Matt/hg/tests/.pytype/pyi/mercurial/shelve.pyi --analyze-annotated --nofail --quick /mnt/c/Users/Matt/hg/mercurial/shelve.py
    File "/mnt/c/Users/Matt/hg/mercurial/shelve.py", line 244, in _verifyandtransform: Function bytestr.__init__ was called with the wrong arguments [wrong-arg-types]
             Expected: (self, ints: Iterable[int])
      Actually passed: (self, ints: Union[KeyError, TypeError, ValueError])
    File "/mnt/c/Users/Matt/hg/mercurial/shelve.py", line 253, in _getversion: Function bytestr.__init__ was called with the wrong arguments [wrong-arg-types]
             Expected: (self, ints: Iterable[int])
      Actually passed: (self, ints: ValueError)
      The following methods aren't implemented on ValueError:
      __iter__

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10122

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -241,7 +241,7 @@ 
                 bin(h) for h in d[b'nodestoremove'].split(b' ')
             ]
         except (ValueError, TypeError, KeyError) as err:
-            raise error.CorruptedState(pycompat.bytestr(err))
+            raise error.CorruptedState(stringutil.forcebytestr(err))
 
     @classmethod
     def _getversion(cls, repo):
@@ -250,7 +250,7 @@ 
         try:
             version = int(fp.readline().strip())
         except ValueError as err:
-            raise error.CorruptedState(pycompat.bytestr(err))
+            raise error.CorruptedState(stringutil.forcebytestr(err))
         finally:
             fp.close()
         return version