[PATCH] py3: use setattr() to assign new class attribute

Pulkit Goyal 7895pulkit at gmail.com
Tue May 17 16:19:20 EDT 2016


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1463443356 -19800
#      Tue May 17 05:32:36 2016 +0530
# Node ID 3087d6aee6923479ce326fcbae4cfa7a261faab1
# Parent  90d84e1e427a9d65aedd870cdb7283f84bb30141
py3: use setattr() to assign new class attribute

The old method produces error 'object does not supports item assignment'.
So setattr() is used to assign a new class attribute via __dict__ .

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -41,7 +41,7 @@
     kw['continuation_ws'] = ' '
     _oldheaderinit(self, *args, **kw)
 
-email.Header.Header.__dict__['__init__'] = _unifiedheaderinit
+setattr(email.header.Header, '__init__', _unifiedheaderinit)
 
 class STARTTLS(smtplib.SMTP):
     '''Derived class to verify the peer certificate for STARTTLS.


More information about the Mercurial-devel mailing list