File tree 2 files changed +5
-5
lines changed
2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -568,15 +568,15 @@ class MapCBORSerializable(CBORSerializable):
568
568
569
569
Basic usage:
570
570
571
- >>> from dataclasses import dataclass
571
+ >>> from dataclasses import dataclass, field
572
572
>>> @dataclass
573
573
... class Test1(MapCBORSerializable):
574
574
... a: str=""
575
575
... b: str=""
576
576
>>> @dataclass
577
577
... class Test2(MapCBORSerializable):
578
578
... c: str=None
579
- ... test1: Test1=Test1( )
579
+ ... test1: Test1=field(default_factory=Test1 )
580
580
>>> t = Test2(test1=Test1(a="a"))
581
581
>>> t
582
582
Test2(c=None, test1=Test1(a='a', b=''))
@@ -600,7 +600,7 @@ class MapCBORSerializable(CBORSerializable):
600
600
>>> @dataclass
601
601
... class Test2(MapCBORSerializable):
602
602
... c: str=field(default=None, metadata={"key": "0", "optional": True})
603
- ... test1: Test1=field(default =Test1() , metadata={"key": "1"})
603
+ ... test1: Test1=field(default_factory =Test1, metadata={"key": "1"})
604
604
>>> t = Test2(test1=Test1(a="a"))
605
605
>>> t
606
606
Test2(c=None, test1=Test1(a='a', b=''))
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ class Test1(MapCBORSerializable):
87
87
@dataclass
88
88
class Test2 (MapCBORSerializable ):
89
89
c : str = None
90
- test1 : Test1 = Test1 ( )
90
+ test1 : Test1 = field ( default_factory = Test1 )
91
91
92
92
t = Test2 (test1 = Test1 (a = "a" ))
93
93
assert t .to_cbor () == "a26163f6657465737431a261616161616260"
@@ -103,7 +103,7 @@ class Test1(MapCBORSerializable):
103
103
@dataclass
104
104
class Test2 (MapCBORSerializable ):
105
105
c : str = field (default = None , metadata = {"key" : "0" , "optional" : True })
106
- test1 : Test1 = field (default = Test1 () , metadata = {"key" : "1" })
106
+ test1 : Test1 = field (default_factory = Test1 , metadata = {"key" : "1" })
107
107
108
108
t = Test2 (test1 = Test1 (a = "a" ))
109
109
assert t .to_primitive () == {"1" : {"0" : "a" , "1" : "" }}
You can’t perform that action at this time.
0 commit comments