[Request] [+ ] D11471: parser: force a `ValueError` to bytes before passing to `error.ParseError`

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Tue Sep 21 15:38:48 UTC 2021


mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I'm not sure what changed before pytype 09-09-2021 (from 04-15-2021), but this
  started getting flagged.  I think there's a pytype bug here, because I don't
  see how `.lower()` can be getting called on a `ValueError` after it is forced to
  a byte string.  That's suppressed for now to make progress.
  
  This fixes:
  
    File "/mnt/c/Users/Matt/hg/mercurial/parser.py", line 219, in unescapestr: Function bytestr.__init__ was called with the wrong arguments [wrong-arg-types]
             Expected: (self, ints: Iterable[int])
      Actually passed: (self, ints: ValueError)
      Attributes of protocol Iterable[int] are not implemented on ValueError: __iter__
    File "/mnt/c/Users/Matt/hg/mercurial/parser.py", line 219, in unescapestr: No attribute 'lower' on ValueError [attribute-error]
      In Union[ValueError, mercurial.pycompat.bytestr]

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/parser.py

CHANGE DETAILS

diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -21,7 +21,6 @@
 from .i18n import _
 from . import (
     error,
-    pycompat,
     util,
 )
 from .utils import stringutil
@@ -216,7 +215,11 @@
         return stringutil.unescapestr(s)
     except ValueError as e:
         # mangle Python's exception into our format
-        raise error.ParseError(pycompat.bytestr(e).lower())
+        # TODO: remove this suppression.  For some reason, pytype 2021.09.09
+        #   thinks .lower() is being called on Union[ValueError, bytes].
+        # pytype: disable=attribute-error
+        raise error.ParseError(stringutil.forcebytestr(e).lower())
+        # pytype: enable=attribute-error
 
 
 def _prettyformat(tree, leafnodes, level, lines):



To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210921/b63b3c0b/attachment.html>


More information about the Mercurial-patches mailing list