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

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Sun Mar 3 04:34:17 EST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG89f01ea906ae: attr: don'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

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



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


More information about the Mercurial-devel mailing list