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

Martijn Pieters mj at zopatista.com
Wed May 18 08:27:54 EDT 2016


LGTM; class dictionaries on new-style objects are proxies and don't
support item assignment. Classes still support attributes, so this is
entirely the correct way of fixing this.

On 17 May 2016 at 21:19, 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__ .
>
> 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



-- 
Martijn Pieters


More information about the Mercurial-devel mailing list