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: Argument Clinic: int with boolean default
Type: enhancement Stage: resolved
Components: Demos and Tools Versions: Python 3.4
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, larry, serhiy.storchaka
Priority: normal Keywords:

Created on 2014-01-16 20:18 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg208304 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-16 20:18
Currently in many functions boolean argument parsed as int, with 'i' code. When converting this to Argument Clinic we can't write just

    interactive: int = False

because C default becomes "Py_False".

Instead we need explicitly specify c_default.

    interactive: int(c_default="0") = False

It would be good if True/False default values be converted to 1/0 C default values for the int type.

I think this is enough common situation.
msg208392 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2014-01-18 09:42
I think these shouldn't be "int", they should be "bool".  "bool" will allow you to use a default of False.  It maps to the "p" format unit, which was new in 3.3.

Back before 3.3, when someone wanted a boolean they just used "i", and relied on the fact that True turned into 1 and False turned into 0.  (Even more so before 2.2, when we didn't even have True and False.)  In theory it's a semantic change, because "i" only accepts ints (and True/False), whereas "p" will accept floats, lists, tuples, dicts, sets... anything with a __bool__.  But the intent of code like this is clear, it's only interested in true/false.  And Python has well-established rules for what is considered a true and false.  So I feel like this change is an improvement.
History
Date User Action Args
2022-04-11 14:57:57adminsetgithub: 64481
2014-01-18 09:42:49larrysetstatus: open -> closed
resolution: wont fix
messages: + msg208392

stage: resolved
2014-01-16 20:18:38serhiy.storchakacreate