-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
bpo-12159: document sys.maxsize limit in len() function reference #17934
Conversation
I think that this is a good addition to the documentation, but the example with |
Doc/library/functions.rst
Outdated
@@ -892,6 +892,9 @@ are always available. They are listed here in alphabetical order. | |||
sequence (such as a string, bytes, tuple, list, or range) or a collection | |||
(such as a dictionary, set, or frozen set). | |||
|
|||
**CPython implementation detail:** ``len`` raises :class:`OverflowError` | |||
on inputs larger than :data:`sys.maxsize`, such as :class:`range`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on inputs larger than :data:`sys.maxsize`, such as :class:`range`. | |
on lengths larger than :data:`sys.maxsize`. |
I don't understand the "such as range()" part. len(range(5)) returns 5, it doesn't fail with overflow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've clarified that this is for cases such as range(2 ** 64)
.
sys.maxsize
limit in function reference for len()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I would prefer to get a second review. @csabella @serhiy-storchaka @JulienPalard: What do you think of this len note?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Since this has been brought up multiple times, I think it's best to document it, especially since __len__
had a note added in the past. Thanks for the patch, @Zac-HD!
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again |
See:
__len__
method but notlen()
, andhttps://bugs.python.org/issue12159