[Python-Dev] CPython crash with '%o' (original) (raw)

Mike Stall jmstall at exchange.microsoft.com
Wed Nov 14 20:16:09 CET 2007


This is my first post, so here's a quick intro: I've recently joined the IronPython team at Microsoft, after about 6 years as a developer on the the .NET runtime (CLR). I'm currently trying to make IronPython match CPython's behavior regarding some % format string to a level of detail not documented by the spec. (http://docs.python.org/lib/typesseq-strings.html) While exploring to determine what CPython's behavior is, I'm hitting a SystemError in CPython. Given the following snippet: class c(long): def oct(self): return '100' x=c(5) oct(x) # expected to print 100 '%o' % x # expected to use print '5' It looks like in CPython, '%o' uses int and so it should ignore oct and print 5. However, I'm hitting an SystemError in CPython with this snippet: Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] onwin32 Type "help", "copyright", "credits" or "license" for more information.

class c(long): ... def oct(self): ... return '100' ... x=c(5) oct(x) # expected to print 100 '100' '%o' % x # expected to use print '5' Traceback (most recent call last): File "", line 1, in SystemError: \loewis\25\python\Objects\stringobject.c:4236: bad argument to internal function Note that if c derives from 'int' instead of 'long', everything works as expected.

  1. Can somebody confirm that '%o' should not use oct and that is uses int instead, and that the correct output from ('%o' % x) is indeed 5?
  2. Should I file a bug for the SystemError exception? Thanks, Mike http://blogs.msdn.com/jmstall

-------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-dev/attachments/20071114/0c5f7eb6/attachment.htm



More information about the Python-Dev mailing list