Skip to content

[rejected AI] Fix BOOL conversion of 0 and 1 - #3849

Closed
Wahib294 wants to merge 1 commit into
pallets:mainfrom
Wahib294:fix-bool-numeric-values
Closed

[rejected AI] Fix BOOL conversion of 0 and 1#3849
Wahib294 wants to merge 1 commit into
pallets:mainfrom
Wahib294:fix-bool-numeric-values

Conversation

@Wahib294

@Wahib294 Wahib294 commented Sep 6, 2026

Copy link
Copy Markdown

BOOL raises AttributeError: 'int' object has no attribute 'strip' when it
receives a number instead of a string. This happens for a boolean option with
default=1 or default=0, for a default_map loaded from a config file
where a boolean came through as a number, and for click.prompt(type=bool)
with a numeric default.

import click
click.BOOL(1)

Click 8.0 through 8.2.1 accepted 0 and 1 through the value in {False, True}
guard added in e79c2b4. #2956 (8.2.2) replaced it with isinstance(value, bool)
while reworking str_to_bool, so numbers now fall through to the string path.

This restores the guard and passes the value through str() before the
lookup, so 0 and 1 convert to False and True again and any other
non-string input produces the usual "is not a valid boolean" error instead of
a traceback.

fixes #3846

@davidism

davidism commented Sep 6, 2026

Copy link
Copy Markdown
Member

@davidism davidism closed this Sep 6, 2026
@davidism davidism added the rejected AI Contribution rejected because of its untrustworthy AI origin label Sep 6, 2026
@davidism davidism changed the title Fix BOOL conversion of 0 and 1 [rejected AI] Fix BOOL conversion of 0 and 1 Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rejected AI Contribution rejected because of its untrustworthy AI origin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rejected AI] BOOL raises AttributeError on numeric input since 8.2.2

2 participants