This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年04月23日 22:53 by Albert.Zeyer, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg159099 - (view) | Author: Albert Zeyer (Albert.Zeyer) * | Date: 2012年04月23日 22:53 | |
```
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.
|
|||
| msg159110 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2012年04月24日 01:45 | |
It's a CPython bug. |
|||
| msg159153 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年04月24日 15:09 | |
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 |
|||
| msg159155 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年04月24日 15:10 | |
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 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:29 | admin | set | github: 58863 |
| 2012年04月24日 15:10:31 | python-dev | set | messages: + msg159155 |
| 2012年04月24日 15:09:28 | python-dev | set | status: open -> closed nosy: + python-dev messages: + msg159153 resolution: fixed stage: resolved |
| 2012年04月24日 14:18:46 | Mark.Shannon | set | nosy:
+ Mark.Shannon |
| 2012年04月24日 13:58:18 | Anthony.Kong | set | nosy:
+ Anthony.Kong |
| 2012年04月24日 01:45:23 | benjamin.peterson | set | messages: + msg159110 |
| 2012年04月23日 22:54:14 | pitrou | set | nosy:
+ benjamin.peterson |
| 2012年04月23日 22:53:32 | Albert.Zeyer | create | |