Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue14658] Overwriting dict.__getattr__ is inconsistent

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Apr 23, 2012, 3:53 PM

Post #1 of 7 (138 views)
Permalink
[issue14658] Overwriting dict.__getattr__ is inconsistent

New submission from Albert Zeyer <albzey [at] googlemail>:

```
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 [at] bugs>
<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


report at bugs

Apr 23, 2012, 3:54 PM

Post #2 of 7 (131 views)
Permalink
[issue14658] Overwriting dict.__getattr__ is inconsistent [In reply to]

Changes by Antoine Pitrou <pitrou [at] free>:


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

_______________________________________
Python tracker <report [at] bugs>
<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


report at bugs

Apr 23, 2012, 6:45 PM

Post #3 of 7 (130 views)
Permalink
[issue14658] Overwriting dict.__getattr__ is inconsistent [In reply to]

Benjamin Peterson <benjamin [at] python> added the comment:

It's a CPython bug.

----------

_______________________________________
Python tracker <report [at] bugs>
<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


report at bugs

Apr 24, 2012, 6:58 AM

Post #4 of 7 (123 views)
Permalink
[issue14658] Overwriting dict.__getattr__ is inconsistent [In reply to]

Changes by Anthony Kong <anthony.hw.kong [at] gmail>:


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

_______________________________________
Python tracker <report [at] bugs>
<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


report at bugs

Apr 24, 2012, 7:18 AM

Post #5 of 7 (123 views)
Permalink
[issue14658] Overwriting dict.__getattr__ is inconsistent [In reply to]

Changes by Mark Shannon <mark [at] hotpy>:


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

_______________________________________
Python tracker <report [at] bugs>
<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


report at bugs

Apr 24, 2012, 8:09 AM

Post #6 of 7 (126 views)
Permalink
[issue14658] Overwriting dict.__getattr__ is inconsistent [In reply to]

Roundup Robot <devnull [at] psf> 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 [at] bugs>
<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


report at bugs

Apr 24, 2012, 8:10 AM

Post #7 of 7 (126 views)
Permalink
[issue14658] Overwriting dict.__getattr__ is inconsistent [In reply to]

Roundup Robot <devnull [at] psf> 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 [at] bugs>
<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

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.