[New-bugs-announce] [issue3729] SystemError on calling len() if __len__() doesn't return an int

Hagen Fürstenau report at bugs.python.org
Fri Aug 29 16:59:08 CEST 2008

New submission from Hagen Fürstenau <hfuerstenau at gmx.net>:

On Python 3.0:

>>> class C:
...     def __len__(self): return "foo"
>>> len(C())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: Objects/longobject.c:433: bad argument to internal function

On Python 2.6 the behaviour is different for old and new-style classes,
with old-style classes giving the more informative error message and
both accepting (and truncating) floats.

I attached a patch for Python 3.0, which refuses everything but ints and
gives an informative error message. Or does the float-truncating
behaviour of Python 2.x need to be preserved?

files: len_check.diff
keywords: patch
messages: 72141
nosy: hagen
severity: normal
status: open
title: SystemError on calling len() if __len__() doesn't return an int
type: behavior
versions: Python 2.6, Python 3.0
Added file: http://bugs.python.org/file11307/len_check.diff

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list