Allow boolean positionals in __post_init__ (#10027)

Closes https://github.com/astral-sh/ruff/issues/10011.
This commit is contained in:
Charlie Marsh 2024-02-18 10:03:17 -05:00 committed by GitHub
parent 235cfb7976
commit e1928be36e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -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)

View file

@ -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