This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Incorrect range checks/documentation in curses
Type: Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: ZackerySpytz, arbor, docs@python, pablogsal, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2020-12-19 00:58 by arbor, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23874 merged serhiy.storchaka, 2020-12-20 21:35
PR 24077 merged serhiy.storchaka, 2021-01-03 21:33
PR 24079 merged serhiy.storchaka, 2021-01-03 22:58
PR 24089 merged serhiy.storchaka, 2021-01-04 10:34
PR 24113 merged serhiy.storchaka, 2021-01-05 07:43
PR 24116 merged serhiy.storchaka, 2021-01-05 12:49
Messages (14)
msg383344 - (view) Author: Robert T McQuaid (arbor) Date: 2020-12-19 00:58
The description of color_pair starts with

curses.color_pair(color_number)

It should be

curses.color_pair(pair_number)
msg383385 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2020-12-19 16:10
Please explain why you believe this is a mistake.
msg383403 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-12-19 21:09
Good catch! And it is not only documentation issue now. Since color numbers and pair numbers use different range checks, this prevents using this function with pair numbers larger that COLORS (should be accepted up to COLOR_PAIRS-1).

Seems there is also other bug which prevents using pair number 0 (constant white on black).
msg384296 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-03 20:51
New changeset 1470edd6131c29b8a09ce012cdfee3afa269d553 by Serhiy Storchaka in branch 'master':
bpo-42681: Fix range checks for color and pair numbers in curses (GH-23874)
https://github.com/python/cpython/commit/1470edd6131c29b8a09ce012cdfee3afa269d553
msg384301 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-03 22:55
New changeset b0ee2b492dbf550fbd2a63b82de0a4dc9d67f32e by Serhiy Storchaka in branch '3.9':
[3.9] bpo-42681: Fix range checks for color and pair numbers in curses (GH-23874). (GH-24077)
https://github.com/python/cpython/commit/b0ee2b492dbf550fbd2a63b82de0a4dc9d67f32e
msg384302 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-01-03 23:51
This change seems to broke some buildbots. For instance:

https://buildbot.python.org/all/#/builders/119/builds/153


======================================================================
ERROR: test_colors_funcs (test.test_curses.TestCurses)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dje/cpython-buildarea/3.8.edelsohn-rhel8-z/build/Lib/test/test_curses.py", line 310, in test_colors_funcs
    curses.pair_content(min(curses.COLOR_PAIRS - 1, 0x7fff))
_curses.error: Argument 1 was out of range. (1..COLOR_PAIRS-1)
----------------------------------------------------------------------
Ran 28 tests in 0.337s
FAILED (errors=1)
1 test failed again:
    test_curses
== Tests result: FAILURE then FAILURE ==
msg384304 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-01-03 23:57
> This change seems to broke some buildbots.

Yep, see also bpo-42789.
msg384309 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-04 08:58
New changeset 82794cacc6073af9bc2b792a5ee21397f4c9037f by Serhiy Storchaka in branch '3.8':
[3.8] [3.9] bpo-42681: Fix range checks for color and pair numbers in curses (GH-23874). (GH-24077) (GH-24079)
https://github.com/python/cpython/commit/82794cacc6073af9bc2b792a5ee21397f4c9037f
msg384371 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-05 07:13
New changeset 59f9b4e4509be67494f3d45489fa55523175ff69 by Serhiy Storchaka in branch 'master':
bpo-42681: Fix test_curses failures related to color pairs (GH-24089)
https://github.com/python/cpython/commit/59f9b4e4509be67494f3d45489fa55523175ff69
msg384388 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-05 12:23
New changeset 9b3a53a8264d4c469a3f3d8c037e74c010be3e5c by Serhiy Storchaka in branch '3.9':
[3.9] bpo-42681: Fix test_curses failures related to color pairs (GH-24089) (GH-24113)
https://github.com/python/cpython/commit/9b3a53a8264d4c469a3f3d8c037e74c010be3e5c
msg384398 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-05 14:04
New changeset e2c847e0c518dd6c63a898b8265ba54b71548bd6 by Serhiy Storchaka in branch '3.8':
[3.8] [3.9] bpo-42681: Fix test_curses failures related to color pairs (GH-24089) (GH-24113) (GH-24116)
https://github.com/python/cpython/commit/e2c847e0c518dd6c63a898b8265ba54b71548bd6
msg384402 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-05 14:33
Well, a simple documentation issue has grown into large and complex changes that fix several bugs.

* Incorrect parameter name in color_pair().
* Incorrectly documented ranges for color and pair numbers.
* Based on incorrect documentation, incorrect checks was implemented in the code.
* It was not caught earlier because most tests were skipped on buildbots.
* BTW ncurses accepts some values outside of the documented ranges.
* But ncurses 6.1 does not accept all values in the documented ranges.
* There were other minor bugs introduced in issue36982.
msg384403 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-01-05 14:50
Thanks a lot Serhiy for the fantastic work!
msg384492 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-01-06 11:32
Great work, thank you Serhiy!
History
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 86847
2021-01-06 11:32:07vstinnersetmessages: + msg384492
2021-01-05 14:50:55pablogsalsetmessages: + msg384403
2021-01-05 14:33:37serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg384402

stage: patch review -> resolved
2021-01-05 14:04:32serhiy.storchakasetmessages: + msg384398
2021-01-05 12:49:20serhiy.storchakasetpull_requests: + pull_request22946
2021-01-05 12:23:47serhiy.storchakasetmessages: + msg384388
2021-01-05 07:43:39serhiy.storchakasetpull_requests: + pull_request22943
2021-01-05 07:13:22serhiy.storchakasetmessages: + msg384371
2021-01-04 10:34:54serhiy.storchakasetpull_requests: + pull_request22920
2021-01-04 08:58:29serhiy.storchakasetmessages: + msg384309
2021-01-03 23:57:30vstinnersetnosy: + vstinner
messages: + msg384304
2021-01-03 23:51:07pablogsalsetnosy: + pablogsal
messages: + msg384302
2021-01-03 22:58:10serhiy.storchakasetpull_requests: + pull_request22913
2021-01-03 22:55:26serhiy.storchakasetmessages: + msg384301
2021-01-03 21:46:49serhiy.storchakasettitle: mistake in curses documentation -> Incorrect range checks/documentation in curses
2021-01-03 21:33:50serhiy.storchakasetpull_requests: + pull_request22911
2021-01-03 20:51:18serhiy.storchakasetmessages: + msg384296
2020-12-20 21:35:03serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request22736
2020-12-19 21:09:18serhiy.storchakasetassignee: docs@python -> serhiy.storchaka
messages: + msg383403
components: + Library (Lib)
versions: + Python 3.8, Python 3.9
2020-12-19 19:49:12rhettingersetnosy: + serhiy.storchaka
2020-12-19 16:10:28ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg383385
2020-12-19 00:58:57arborcreate