A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-March/062578.html below:

[Python-Dev] __dict__ strangeness

[Python-Dev] __dict__ strangeness [Python-Dev] __dict__ strangenessGeorg Brandl g.brandl at gmx.net
Sat Mar 18 18:57:12 CET 2006
[moving to python-dev]

Alex Martelli wrote:
> Georg Brandl <g.brandl-nospam at gmx.net> wrote:
> 
>> can someone please tell me that this is correct and why:
> 
> IMHO, it is not correct: it is a Python bug (and it would be nice to fix
> it in 2.5).

Fine. Credits go to Michal Kwiatkowski for discovering that in bug #1448042
which I closed out of ignorance ;)

>> >>> class C(object):
>> ...     pass
>> ...
>> >>> c = C()
>> >>> c.a = 1
>> >>> c.__dict__
>> {'a': 1}
>> >>> c.__dict__ = {}
>> >>> c.a
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>> AttributeError: 'C' object has no attribute 'a'
> 
> So far so good, I think we agree;-).
Yes.

>> >>> class D(object):
>> ...     __dict__ = {}
>> ...
>> >>> d = D()
>> >>> d.a = 1
>> >>> d.__dict__
>> {}
>> >>> d.__dict__ = {}
>> >>> d.a
>> 1
> 
> Yep, that's the bug, fully reproducible in 2.3 and 2.4.  FWIW, mucking
> around with gc.getreferrers (with a more uniquely identifiable value for
> d.a;-) shows a dictionary "somewhere" with keys 'a' and '__dict__'...

Georg

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4