[Python-Dev] [Python-checkins] cpython (3.2): don't use a slot wrapper from a different special method (closes #14658) (original) (raw)
Ethan Furman ethan at stoneleaf.us
Tue Apr 24 18:33:38 CEST 2012
- Previous message: [Python-Dev] [Python-checkins] cpython (3.2): don't use a slot wrapper from a different special method (closes #14658)
- Next message: [Python-Dev] [Python-checkins] cpython (3.2): don't use a slot wrapper from a different special method (closes #14658)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Mark Shannon wrote:
Benjamin Peterson wrote:
2012/4/24 Mark Shannon <mark at hotpy.org>:
I'm not happy with this fix.
It's not perfect, but it's an improvement.
Admittedly code like:
class S(str): getattr_ = str._add s = S('a') print(S.b) My typo, should be: print(s.b) (Instance not class) is a little weird. But I think it should work (ie print 'ab') properly.
I can easily believe I'm missing something, but here are the results with the patch in place:
{'x': 42} 42 {'x': 42} 42 ab
and here's the code:
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)
class S(str): getattr = str.add s = S('a') print(s.b)
Ethan
- Previous message: [Python-Dev] [Python-checkins] cpython (3.2): don't use a slot wrapper from a different special method (closes #14658)
- Next message: [Python-Dev] [Python-checkins] cpython (3.2): don't use a slot wrapper from a different special method (closes #14658)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]