
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2015-04-23 10:33 byserhiy.storchaka, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| clinic_boolint_converter.patch | serhiy.storchaka,2015-04-23 10:33 | review | ||
| clinic_boolint_converter_2.patch | serhiy.storchaka,2015-05-12 10:52 | review | ||
| clinic-boolint-converter-3.patch | serhiy.storchaka,2017-03-04 20:28 | |||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 485 | merged | serhiy.storchaka,2017-03-05 21:43 | |
| Messages (9) | |||
|---|---|---|---|
| msg241860 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2015-04-23 10:33 | |
The 'i' format unit is often used for semantically boolean values. When the parameter has a default value, in Argument clinic you should specify it twice, as Python and C values: closefd: int(c_default="1") = Trueor keepends: int(py_default="False") = 0Proposed patch adds the boolint converter which makes a conversion for you. closefd: boolint = True keepends: boolint = False | |||
| msg241882 -(view) | Author: Larry Hastings (larry)*![]() | Date: 2015-04-23 19:40 | |
I think this is silly.Python has a well-understood concept of "truth":https://docs.python.org/3/library/stdtypes.html#truth-value-testingI assert that the reason people used the "i" format unit for what are really boolean values is because a) the "p" format unit wasn't added until very recently, and b) they were lazy and it was easy to copy-and-paste from other code.Rather than perpetuate these misguided hacks, when converting code to Argument Clinic we should convert them to properly support truth as defined in Python. | |||
| msg241883 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2015-04-23 19:56 | |
I consider this as transitional style, for simpler converting to Argument Clinic without changing the behaviour. In future it can be replaced with bool.But the bool converter has a downside. It is harder to extend it. We can't add a support of say a tuple, or callable, or string, or ternary logic value without potential breaking some code. I propose first convert all semantic boolean ints to the boolint converter, and then, after fundamental analysis, replace boolint with bool if there is no any sense to extend concrete parameter. | |||
| msg242008 -(view) | Author: Tal Einat (taleinat)*![]() | Date: 2015-04-25 08:31 | |
If this was for internal use only, intended to ease the transition to Argument Clinic, then extensibility isn't an issue.An upside to this is that it would make it easy in the future to find all of the places in the stdlib using integers instead of bools.A downside is that "boolint" isn't a very obvious name IMO. | |||
| msg242010 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2015-04-25 09:30 | |
I proposed boolint or intbool. Are there better variants?An alternative is add accept={int} parameter to the bool converter. But this will complicate the implementation and the use without the need. | |||
| msg242140 -(view) | Author: Tal Einat (taleinat)*![]() | Date: 2015-04-27 17:53 | |
If I was writing a function/method with a conceptually boolean parameter (True/False), I wouldn't want that to accept any Python object. For example, I would want passing a tuple or list to raise a TypeError. But according to the docs[1], that's what the 'p' converter does.If Python had a separate boolean type, this would be simple, but bool is a subclass of int, and it is easy to get a 0 or a 1 instead of True or False without noticing. So it seems reasonable when using the C API to accept an int when you want to get a boolean. I'd want a converter to convert it to a C bool, of course. | |||
| msg242957 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2015-05-12 10:52 | |
Updated to the tip. Used new converter in recently converted _tkinter and _codecs modules. Now it is used 30 times. | |||
| msg288993 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-03-04 20:28 | |
Updated patch uses bool(accept={int}) rather of boolint. It also updates more functions converted to Argument Clinic. | |||
| msg290218 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-03-24 22:25 | |
New changeset202fda55c2dffe27125703225e5af92254602dc6 by Serhiy Storchaka in branch 'master':bpo-24037: Add Argument Clinic converter `bool(accept={int})`. (#485)https://github.com/python/cpython/commit/202fda55c2dffe27125703225e5af92254602dc6 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:16 | admin | set | github: 68225 |
| 2017-03-24 22:25:30 | serhiy.storchaka | set | messages: +msg290218 |
| 2017-03-17 21:18:08 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2017-03-17 21:06:24 | larry | set | pull_requests: -pull_request601 |
| 2017-03-17 21:00:34 | larry | set | pull_requests: +pull_request601 |
| 2017-03-05 21:43:13 | serhiy.storchaka | set | pull_requests: +pull_request398 |
| 2017-03-04 20:28:22 | serhiy.storchaka | set | files: +clinic-boolint-converter-3.patch messages: +msg288993 versions: + Python 3.7, - Python 3.5 |
| 2015-05-12 10:52:01 | serhiy.storchaka | set | files: +clinic_boolint_converter_2.patch messages: +msg242957 |
| 2015-04-27 17:53:07 | taleinat | set | messages: +msg242140 |
| 2015-04-25 09:30:54 | serhiy.storchaka | set | messages: +msg242010 |
| 2015-04-25 08:31:39 | taleinat | set | nosy: +taleinat messages: +msg242008 |
| 2015-04-23 19:56:46 | serhiy.storchaka | set | messages: +msg241883 |
| 2015-04-23 19:40:38 | larry | set | messages: +msg241882 |
| 2015-04-23 10:33:08 | serhiy.storchaka | create | |