D6048: attr: don't attempt to .encode() a str on Python 2
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Sat Mar 2 21:26:37 UTC 2019
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
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