# HG changeset patch # User Gregory Szorc # Date 2019-03-02 20:55:29 # Node ID 89f01ea906ae6471c18caaa08739f88cf19823e6 # Parent b275dbb60089edef01a61d52adb3f7e75a68480a attr: don't attempt to .encode() a str on Python 2 Otherwise it coerces automatically. Differential Revision: https://phab.mercurial-scm.org/D6048 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 @@ def _add_init(cls, frozen): # 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 = "".format( sha1.hexdigest() )