changeset 36110:230489fc0b41

py3: catch TypeError during template operations 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. Differential Revision: https://phab.mercurial-scm.org/D2156
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 11 Feb 2018 16:16:43 -0800
parents 361276a36d49
children b44a47214122
files mercurial/templatekw.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatekw.py	Sun Feb 11 16:08:11 2018 -0800
+++ b/mercurial/templatekw.py	Sun Feb 11 16:16:43 2018 -0800
@@ -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