New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SystemError on calling len() if __len__() doesn't return an int #47979
Comments
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, I attached a patch for Python 3.0, which refuses everything but ints and |
What about using PyNumber_AsSsize_t? it uses PyNumber_Index to accept |
Sounds ok, but then you get a more generic "object cannot be interpreted |
Of course we can do both: Accept integral-like types and reset the Review carefully - I'm a newbie! ;-) |
Not bad! some remarks though:
+ else if (PyErr_ExceptionMatches(PyExc_TypeError))
|
That is *not* wanted. We had a discussion on the list about changing the |
In the latest list message I could find Guido wanted len() to lie: http://mail.python.org/pipermail/python-3000/2008-May/013387.html Has this been resolved in bpo-2723? |
True. However, it's no pronouncement either. I suggest bringing it up on |
There seems to be a pronouncement now |
Fixed in bpo-5137. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: