Benjamin Peterson wrote:
2012/4/24 Mark Shannon <m...@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)
This doesn't work.


is a little weird.
But I think it should work (ie print 'ab') properly.

This works without the patch.

class S(str):
  __getattribute__ = str.__add__
s = S('a')
print(S.b)

Same typo,
this does work (with correct spelling :) )

Does it?

$ cat > x.py
class S(str):
  __getattribute__ = str.__add__
s = S('a')
print(S.b)

$ python3 x.py
Traceback (most recent call last):
  File "x.py", line 4, in <module>
    print(S.b)
AttributeError: type object 'S' has no attribute 'b'

(Prints 'ab')

Also "slot wrapper" is a low-level implementation detail and
shouldn't impact the language semantics.

dict.__getitem__ is a slot wrapper; dict.__getitem__ is not.
str.__getitem__ is a slot wrapper; list.__getitem__ is not.
If any of these change then the semantics of the language changes.




_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to