diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_boolean_trap/FBT.py b/crates/ruff_linter/resources/test/fixtures/flake8_boolean_trap/FBT.py index cdb8a97db94d7..e4dcf05345856 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_boolean_trap/FBT.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_boolean_trap/FBT.py @@ -119,3 +119,16 @@ def func(x: bool): settings(True) + + +from dataclasses import dataclass, InitVar + + +@dataclass +class Fit: + force: InitVar[bool] = False + + def __post_init__(self, force: bool) -> None: + print(force) + +Fit(force=True) diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs index 5f8f7a5dd9cc7..49f61539e8d4e 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs @@ -45,7 +45,7 @@ pub(super) fn is_allowed_func_call(name: &str) -> bool { /// Returns `true` if a function definition is allowed to use a boolean trap. pub(super) fn is_allowed_func_def(name: &str) -> bool { - matches!(name, "__setitem__") + matches!(name, "__setitem__" | "__post_init__") } /// Returns `true` if an argument is allowed to use a boolean trap. To return