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.

Author arigo
Recipients arigo
Date 2011-02-07.18:46:33
SpamBayes Score 1.27929e-09
Marked as misclassified No
Message-id <1297104394.76.0.0164852469273.issue11145@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2011-02-07 18:46:34arigosetrecipients: + arigo
2011-02-07 18:46:34arigosetmessageid: <1297104394.76.0.0164852469273.issue11145@psf.upfronthosting.co.za>
2011-02-07 18:46:33arigolinkissue11145 messages
2011-02-07 18:46:33arigocreate