Which objects are expanded by double-star ** operator?

Ian Kelly ian.g.kelly at gmail.com
Tue Jun 8 10:36:00 EDT 2010


On Tue, Jun 8, 2010 at 4:21 AM, Steven D'Aprano
<steve at remove-this-cybersource.com.au> wrote:
> On Mon, 07 Jun 2010 15:04:35 -0600, Ian Kelly wrote:
>
>> I don't think that what you want to do here is possible.  It appears to
>> be hard-coded and not affected by subclassing, as evidenced by the
>> following snippet:
>>
>> class NonDict(dict):
>>     for attr in dict.__dict__:
>>         if attr not in ('__init__', '__new__',):
>>             locals()[attr] = None
>
>
> I'm afraid your test is invalid. As the documentation states, you CANNOT
> write to locals() -- the change doesn't stick. This is nothing to do with
> dicts.

Huh, good point.  But actually the docs just say that the changes
aren't guaranteed to stick, and in the case of my test I inspected the
class and the methods were indeed replaced with None.  In fact, when I
first wrote it, I didn't include the if statement and got a TypeError
when I tried to construct an instance.

Cheers,
Ian



More information about the Python-list mailing list