Mailing List Archive

[issue14658] Overwriting dict.__getattr__ is inconsistent
New submission from Albert Zeyer <albzey@googlemail.com>:

```
class Foo1(dict):
def __getattr__(self, key): return self[key]
def __setattr__(self, key, value): self[key] = value

class Foo2(dict):
__getattr__ = dict.__getitem__
__setattr__ = dict.__setitem__

o1 = Foo1()
o1.x = 42
print(o1, o1.x)

o2 = Foo2()
o2.x = 42
print(o2, o2.x)
```

With CPython 2.5, 2.6 (similarly in 3.2), I get:
({'x': 42}, 42)
({}, 42)

With PyPy 1.5.0, I get the expected output::
({'x': 42}, 42)
({'x': 42}, 42)

I asked this also on SO: http://stackoverflow.com/questions/6305267/python-inconsistence-in-the-way-you-define-the-function-setattr

>From the answers, I am not exactly sure wether this is considered as a bug in CPython or not. Anyway, I just wanted to post this here.

----------
components: None
messages: 159099
nosy: Albert.Zeyer
priority: normal
severity: normal
status: open
title: Overwriting dict.__getattr__ is inconsistent
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14658>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue14658] Overwriting dict.__getattr__ is inconsistent [ In reply to ]
Changes by Antoine Pitrou <pitrou@free.fr>:


----------
nosy: +benjamin.peterson

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14658>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue14658] Overwriting dict.__getattr__ is inconsistent [ In reply to ]
Benjamin Peterson <benjamin@python.org> added the comment:

It's a CPython bug.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14658>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue14658] Overwriting dict.__getattr__ is inconsistent [ In reply to ]
Changes by Anthony Kong <anthony.hw.kong@gmail.com>:


----------
nosy: +Anthony.Kong

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14658>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue14658] Overwriting dict.__getattr__ is inconsistent [ In reply to ]
Changes by Mark Shannon <mark@hotpy.org>:


----------
nosy: +Mark.Shannon

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14658>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue14658] Overwriting dict.__getattr__ is inconsistent [ In reply to ]
Roundup Robot <devnull@psf.upfronthosting.co.za> added the comment:

New changeset 971865f12377 by Benjamin Peterson in branch '3.2':
don't use a slot wrapper from a different special method (closes #14658)
http://hg.python.org/cpython/rev/971865f12377

New changeset 0c1c8f8955d8 by Benjamin Peterson in branch 'default':
merge 3.2 (#14658)
http://hg.python.org/cpython/rev/0c1c8f8955d8

----------
nosy: +python-dev
resolution: -> fixed
stage: -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14658>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue14658] Overwriting dict.__getattr__ is inconsistent [ In reply to ]
Roundup Robot <devnull@psf.upfronthosting.co.za> added the comment:

New changeset e3eda2d91e93 by Benjamin Peterson in branch '2.7':
don't use a slot wrapper from a different special method (closes #14658)
http://hg.python.org/cpython/rev/e3eda2d91e93

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14658>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com