The Wayback Machine - https://web.archive.org/web/20250621181717/https://github.com/python/cpython/pull/21422
Skip to content

Fix error in docstrings in bisect module #21422

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

Merged
merged 1 commit into from
Jul 11, 2020

Conversation

jdavcs
Copy link
Contributor

@jdavcs jdavcs commented Jul 9, 2020

The docstrings for bisect_right() and bisect_left() contain sample code that has a bug: a.insert(x) should be a.insert(i, x).

Not creating/citing an issue as this is minor.

The docstrings for `bisect_right()` and `bisect_left()` contain sample
code that has a bug: `a.insert(x)` should be `a.insert(i, x)`.
@nanjekyejoannah
Copy link
Contributor

Thanks for your contribution @ic4f .

@jdavcs
Copy link
Contributor Author

jdavcs commented Jul 11, 2020

Thank you for approving/merging!

arun-mani-j pushed a commit to arun-mani-j/cpython that referenced this pull request Jul 21, 2020
The docstrings for `bisect_right()` and `bisect_left()` contain sample
code that has a bug: `a.insert(x)` should be `a.insert(i, x)`.
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Aug 20, 2020
The docstrings for `bisect_right()` and `bisect_left()` contain sample
code that has a bug: `a.insert(x)` should be `a.insert(i, x)`.
xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
The docstrings for `bisect_right()` and `bisect_left()` contain sample
code that has a bug: `a.insert(x)` should be `a.insert(i, x)`.
@petulla
Copy link

petulla commented Jan 2, 2021

@ic4f

One thing I noticed in this docstring.

Is this correct to say?

The return value i is such that all e in a[:i] have e < x, and all e in
    a[i:] have e >= x.  So if x already appears in the list, a.insert(i, x) will
    insert just before the leftmost x already there.

If a[i:] includes e, and i is the left-most value in the list, then isn't it true instead that:

if x already appears in the list, a.insert(i, x) will insert at the same place as the leftmost x already there.

@jdavcs
Copy link
Contributor Author

jdavcs commented Jan 2, 2021

@petulla, I suppose the alternative wording is not wrong. However, the original seems more correct to me. I think the implied meaning here is insertion point, not insertion index - i.e., if I think of it as a row of items, I'll be inserting before or after an item, not in place of an item (which would be a swap). So, it describes the end result of the insert operation - i.e., what the resulting sequence will be, not the first step in the algorithm to achieve that sequence (in which case insertion index would be appropriate).

@petulla
Copy link

petulla commented Jan 2, 2021

I see, that makes sense.

The wording as it is confusing though. I don't think it articulates that case. It does seem like it's giving the insertion point, i, where the element already exists.

@jdavcs
Copy link
Contributor Author

jdavcs commented Jan 2, 2021

If the wording seems not quite right, you might consider opening an issue, see what the community thinks. There's hardly a perfectly worded docstring :)

@petulla
Copy link

petulla commented Jan 2, 2021

Where can issues be opened? I only saw the possibility for PRs, which I'm happy to do but an issue would be best.

@jdavcs
Copy link
Contributor Author

jdavcs commented Jan 2, 2021

The issue tracker: https://bugs.python.org/. Also, this is very helpful as a general intro: https://devguide.python.org/#contributing

@nanjekyejoannah
Copy link
Contributor

I agree with @ic4f , open an issue on bpo or email python-dev with your suggestions if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants