D2156: py3: catch TypeError during template operations

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Mon Feb 12 02:36:06 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Two places in this code Python 3 changed from raising ValueError
  to TypeError. So catch the addition exceptions.
  
  IMO this code might be better off performing type sniffing. But
  I'm not sure the implications of changing that.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/templatekw.py

CHANGE DETAILS

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -192,11 +192,15 @@
     def one(v, tag=name):
         try:
             vmapping.update(v)
-        except (AttributeError, ValueError):
+        # Python 2 raises ValueError if the type of v is wrong. Python
+        # 3 raises TypeError.
+        except (AttributeError, TypeError, ValueError):
             try:
+                # Python 2 raises ValueError trying to destructure an e.g.
+                # bytes. Python 3 raises TypeError.
                 for a, b in v:
                     vmapping[a] = b
-            except ValueError:
+            except (TypeError, ValueError):
                 vmapping[name] = v
         return templ(tag, **pycompat.strkwargs(vmapping))
     lastname = 'last_' + name



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list