While merging the trunk changes into the p3yk branch, I discovered what I think is a bug in the stream codecs. It's easily reproduced in the trunk: in Lib/codecs.py, make the 'Codec' class new-style. Then, suddenly, test_codecs will crash with an exception like this:

======================================================================
ERROR: test_basics (test.test_codecs.BasicUnicodeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/thomas/python/python/trunk/Lib/test/test_codecs.py", line 1089, in test_basics
    writer = codecs.getwriter(encoding)(q)
  File "/home/thomas/python/python/trunk/Lib/codecs.py", line 296, in __init__
    self.stream = stream
TypeError: readonly attribute

Looking at the class, it's hard to tell how it's suddenly a read-only attribute, until you figure out which codec it breaks with: big5. Which is defined in encodings.big5, as a subclass of codecs.Codec, _multibytecodec.MultibyteStreamWriter and codecs.StreamWriter. And _multibytecodec.MultibyteStreamWriter is a new-style class (as it's defined in C) with a read-only 'stream' attribute. The conflicting attribute is silently masked by Python, since classic classes ignore two-thirds of the descriptor protocol (setting and deleting), but it jumps right out when all classes become new-style.

I'm not sure whether this attribute conflict is on purpose or not, but since it will break in the future, I suggest it gets fixed. It *looks* like renaming the _MultibyteStreamWriter attribute is the easiest solution, but I don't know which API has precedence. (One of the two was added fairly recently, at least, since it didn't break in the p3yk branch until I merged in the last few months' worth of changes :)

--
Thomas Wouters <[EMAIL PROTECTED]>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
_______________________________________________
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