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: type casting of bool
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: AlexWaygood, aziz, josh.r
Priority: normal Keywords:

Created on 2021-12-15 11:21 by aziz, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg408595 - (view) Author: aziz (aziz) Date: 2021-12-15 11:21
>>> st = "True"
>>> bool(st)
True
>>> st = "False"
>>> bool(st)
True
>>> 
>>> stk = "False"
>>> bool(stk)
True
>>> eval(stk)
False
msg408599 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2021-12-15 12:34
Hi! Your message here is a little unclear. Are you proposing a new feature (an enhancement), or filing a bug report?

In either case, I'm afraid this behavior is very unlikely to change. In general, strings in Python are always considered truthy unless they are empty, even if they are the literal string "False" or "0". This is a very important principle in Python, and changing it would raise serious backwards-compatibility concerns.

You can read more about truth-value testing here: https://docs.python.org/3/library/stdtypes.html#truth-value-testing
msg408669 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2021-12-16 03:40
Agreed, this is not a bug. The behavior of the bool constructor is not a parser (unlike, say, int), it's a truthiness detector. Non-empty strings are always truthy, by design, so both "True" and "False" are truthy strings. There's no bug to address here.
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90240
2021-12-16 03:40:31josh.rsetstatus: pending -> closed

nosy: + josh.r
messages: + msg408669

resolution: not a bug
stage: resolved
2021-12-15 12:34:29AlexWaygoodsetstatus: open -> pending

nosy: + AlexWaygood
messages: + msg408599

components: - 2to3 (2.x to 3.x conversion tool)
type: enhancement ->
2021-12-15 11:21:17azizcreate