New submission from Armin Rigo <ar...@users.sourceforge.net>: 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 ---------- components: Interpreter Core messages: 128148 nosy: arigo priority: normal severity: normal status: open title: '%o' % user-defined instance versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11145> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com