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

login
register
mail settings
Submitter phabricator
Date March 3, 2019, 9:34 a.m.
Message ID <3dfcd344e3081bd61167abfb18042a8c@localhost.localdomain>
Download mbox | patch
Permalink /patch/39014/
State Not Applicable
Headers show

Comments

phabricator - March 3, 2019, 9:34 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG89f01ea906ae: attr: don&#039;t attempt to .encode() a str on Python 2 (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6048?vs=14297&id=14313

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()
     )