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
Truncate __len__() at sys.maxsize #46975
Comments
On Tue, Apr 29, 2008 at 10:36 PM, Guido van Rossum <guido@python.org>
http://mail.python.org/pipermail/python-3000/2008-April/013343.html With attached patch given class x:
def __len__(self):
return 2**100 len(x()) and len(range(2**100)) will return sys.maxsize. |
Wouldn't it be better to raise OverflowError or somesuch? |
On Wed, Apr 30, 2008 at 2:32 AM, Raymond Hettinger
Thats what the current code does. I don't know what Guido's full Here is a quote from another message: """ I suspect, however, that part of Java's motivation for this behavior |
Gasp, having len() return something else than the true container size |
If you're interested I asked a Java news group: |
Well apparently the Java guys think raising an exception would have been """ The ReturnValueTooBigException could even have a method declared as |
I think returning sys.{maxint,maxsize} in this case is a plain lie. Barring drastic language changes (such as having objects representing """OverflowError: Python int too large to convert to C ssize_t""" I've attached a simple patch (modified from Alexander's) to raise: """OverflowError: Length too large""" (I thought about "Object too large", but our problem is actually that |
Agreed, having it lie about the size is the WORST possible behavior But I must've missed something, why can't __len__ return the correct |
On Sun, May 11, 2008 at 6:38 PM, Gregory P. Smith
The problem is the C signature of the sq_length slot: typedef Py_ssize_t (*lenfunc)(PyObject *); |
I'm also absolutely against having len() lying to me. This would be a |
Most people disagree with the original idea (len.diff: truncate the I don't like rbp's patch: replace verbose error message ("Python int I dislike both patches. Can we close this issue with |
Initial proposition (len.diff) was rejected. If you want to change |
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: