Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Unreleased

- `BOOL` converts `0` and `1` to `False` and `True` again instead of raising
`AttributeError`. Regression introduced in `8.2.2` by {pr}`2956`.
{issue}`3846`

## Version 8.5.0

Released 2026-08-24
Expand Down
6 changes: 3 additions & 3 deletions src/click/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,9 @@ def str_to_bool(value: str | bool) -> bool | None:

Returns `None` if the value does not match any known boolean state.
"""
if isinstance(value, bool):
return value
return BoolParamType.bool_states.get(value.strip().lower())
if value in {False, True}:
return bool(value)
return BoolParamType.bool_states.get(str(value).strip().lower())

def convert(
self, value: t.Any, param: Parameter | None, ctx: Context | None
Expand Down
2 changes: 2 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ def cli(on):
(True, [], True),
(False, ["--f"], True),
(False, [], False),
(1, [], True),
(0, [], False),
# Boolean flags have a 3-states logic.
# See: https://github.com/pallets/click/issues/3024#issue-3285556668
(None, ["--f"], True),
Expand Down