Patchwork D6048: attr: don't attempt to .encode() a str on Python 2

login
register
mail settings
Submitter phabricator
Date March 2, 2019, 9:26 p.m.
Message ID <differential-rev-PHID-DREV-h4wtfx4oftgc6vlnxoxi-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/38998/
State Superseded
Headers show

Comments

phabricator - March 2, 2019, 9:26 p.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Otherwise it coerces automatically.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/thirdparty/attr/_make.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/thirdparty/attr/_make.py b/mercurial/thirdparty/attr/_make.py
--- a/mercurial/thirdparty/attr/_make.py
+++ b/mercurial/thirdparty/attr/_make.py
@@ -555,7 +555,10 @@ 
 
     # We cache the generated init methods for the same kinds of attributes.
     sha1 = hashlib.sha1()
-    sha1.update(repr(attrs).encode("utf-8"))
+    r = repr(attrs)
+    if not isinstance(r, bytes):
+        r = r.encode('utf-8')
+    sha1.update(r)
     unique_filename = "<attrs generated init {0}>".format(
         sha1.hexdigest()
     )