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

Augie Fackler raf at durin42.com
Mon May 23 22:25:46 EDT 2016


> On May 17, 2016, at 4:19 PM, Pulkit Goyal <7895pulkit at gmail.com> wrote:
> 
> # 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__ .

Out of curiosity, did you try simply not wrapping email.header.Header.__init__ on python 3? Based on the commentary in the docstring, it looks like it shouldn’t be required at all there.

> 
> 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.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20160523/7bf7e85a/attachment.sig>


More information about the Mercurial-devel mailing list