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 "<stdin>", line 1, in <module>
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

_______________________________________________
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