Patchwork D2156: py3: catch TypeError during template operations

login
register
mail settings
Submitter phabricator
Date Feb. 13, 2018, 2:47 a.m.
Message ID <4fd6117884e68d624d0aeebade996b41@localhost.localdomain>
Download mbox | patch
Permalink /patch/27759/
State Not Applicable
Headers show

Comments

phabricator - Feb. 13, 2018, 2:47 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG230489fc0b41: py3: catch TypeError during template operations (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2156?vs=5457&id=5580

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

AFFECTED FILES
  mercurial/templatekw.py

CHANGE DETAILS




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

Patch

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