Skip to content

Commit

Permalink
Allow boolean positionals in __post_init__ (#10027)
Browse files Browse the repository at this point in the history
Closes #10011.
charliermarsh authored Feb 18, 2024
1 parent 235cfb7 commit e1928be
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e1928be

Please sign in to comment.