Message128148
The expression '%o' % x, where x is a user-defined instance, usually ignores a user-defined __oct__() method. I suppose that's fine; assuming this is the expected behavior, then the present issue is about the "usually" in my previous sentence.
If 'x' is an instance of a subclass of 'long', then the __oct__() is called. It must be specifically a 'long' -- not, say, 'int' or 'str' or 'object'. Moreover, there is a test in test_format.py (class Foobar) that checks that if this __oct__() returns a non-string, then we get a nice TypeError. That's already strange -- why is __oct__() called in the first place? But trying out more I get (CPython 2.7.1):
>>> class X(long):
... def __oct__(self):
... return 'abc'
...
>>> '%o' % X()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: ../trunk/Objects/stringobject.c:4035: bad argument to internal function |
|
Date |
User |
Action |
Args |
2011-02-07 18:46:34 | arigo | set | recipients:
+ arigo |
2011-02-07 18:46:34 | arigo | set | messageid: <1297104394.76.0.0164852469273.issue11145@psf.upfronthosting.co.za> |
2011-02-07 18:46:33 | arigo | link | issue11145 messages |
2011-02-07 18:46:33 | arigo | create | |
|