Fixed bug in dataclass logic that reported spurious error when initializing attribute with field(init=False).

This commit is contained in:
Eric Traut 2020-07-23 07:34:58 -07:00
parent 077139fe66
commit 33acf3cb88
2 changed files with 13 additions and 0 deletions

View File

@ -1776,6 +1776,7 @@ export function createTypeEvaluator(importLookup: ImportLookup, printTypeFlags:
(p) => p.hasDefault && p.includeInInit
);
if (
includeInInit &&
!hasDefaultValue &&
firstDefaultValueIndex >= 0 &&
firstDefaultValueIndex < insertIndex

View File

@ -31,3 +31,15 @@ test = Child(prop_2="test", prop_4="hi")
assert test.prop_1 == "test"
assert test.prop_2 == "test"
@dataclass
class HandshakeMessage:
reset_reason_hex: str
reset_data_hex: str
device_id: str = field(default="")
reset_reason: str = field(init=False)
reset_data: str = field(init=False)
def __post_init__(self):
reset_reason = "calculated value"
reset_data = "calculated value"