File tree 3 files changed +26
-11
lines changed 3 files changed +26
-11
lines changed Original file line number Diff line number Diff line change @@ -17,12 +17,13 @@ v4.20.1 (2023-03-??)
17
17
18
18
Fixed
19
19
^^^^^
20
- - Allow ``discard_init_args_on_class_path_change `` to handle more nested contexts `#247
21
- <https://github.com/omni-us/jsonargparse/issues/247> `__.
22
-
23
20
- Dump not working for partial callable with return instance
24
21
`pytorch-lightning#15340 (comment)
25
22
<https://github.com/Lightning-AI/lightning/issues/15340#issuecomment-1439203008> `__.
23
+ - Allow ``discard_init_args_on_class_path_change `` to handle more nested
24
+ contexts `#247 <https://github.com/omni-us/jsonargparse/issues/247 >`__.
25
+ - Failure with dataclasses that have field with ``init=False `` `#252
26
+ <https://github.com/omni-us/jsonargparse/issues/252> `__.
26
27
27
28
28
29
v4.20.0 (2023-02-20)
Original file line number Diff line number Diff line change @@ -416,14 +416,15 @@ def add_dataclass_arguments(
416
416
added_args : List [str ] = []
417
417
params = {p .name : p for p in get_signature_parameters (theclass , None , logger = self .logger )}
418
418
for field in dataclasses .fields (theclass ):
419
- self ._add_signature_parameter (
420
- group ,
421
- nested_key ,
422
- params [field .name ],
423
- added_args ,
424
- fail_untyped = fail_untyped ,
425
- default = defaults .get (field .name , inspect_empty ),
426
- )
419
+ if field .name in params :
420
+ self ._add_signature_parameter (
421
+ group ,
422
+ nested_key ,
423
+ params [field .name ],
424
+ added_args ,
425
+ fail_untyped = fail_untyped ,
426
+ default = defaults .get (field .name , inspect_empty ),
427
+ )
427
428
428
429
return added_args
429
430
Original file line number Diff line number Diff line change @@ -1615,6 +1615,19 @@ class MyDataClass:
1615
1615
self .assertRaises (ArgumentError , lambda : parser .parse_args ([]))
1616
1616
1617
1617
1618
+ def test_dataclass_field_init_false (self ):
1619
+
1620
+ @dataclasses .dataclass
1621
+ class DataInitFalse :
1622
+ p1 : str = '-'
1623
+ p2 : str = dataclasses .field (init = False )
1624
+
1625
+ parser = ArgumentParser (exit_on_error = False )
1626
+ added = parser .add_dataclass_arguments (DataInitFalse , 'd' )
1627
+ self .assertEqual (added , ['d.p1' ])
1628
+ self .assertEqual (parser .get_defaults (), Namespace (d = Namespace (p1 = '-' )))
1629
+
1630
+
1618
1631
def test_dataclass_field_default_factory (self ):
1619
1632
1620
1633
@dataclasses .dataclass
You can’t perform that action at this time.
0 commit comments