@@ -503,8 +503,8 @@ class Root(Signed):
503
503
"""A container for the signed part of root metadata.
504
504
505
505
Attributes:
506
- consistent_snapshot: A boolean indicating whether the repository
507
- supports consistent snapshots.
506
+ consistent_snapshot: An optional boolean indicating whether the
507
+ repository supports consistent snapshots.
508
508
keys: A dictionary that contains a public key store used to verify
509
509
top level roles metadata signatures::
510
510
@@ -534,9 +534,9 @@ def __init__(
534
534
version : int ,
535
535
spec_version : str ,
536
536
expires : datetime ,
537
- consistent_snapshot : bool ,
538
537
keys : Dict [str , Key ],
539
538
roles : Dict [str , Role ],
539
+ consistent_snapshot : Optional [bool ] = None ,
540
540
unrecognized_fields : Optional [Mapping [str , Any ]] = None ,
541
541
) -> None :
542
542
super ().__init__ (version , spec_version , expires , unrecognized_fields )
@@ -548,7 +548,7 @@ def __init__(
548
548
def from_dict (cls , root_dict : Dict [str , Any ]) -> "Root" :
549
549
"""Creates Root object from its dict representation."""
550
550
common_args = cls ._common_fields_from_dict (root_dict )
551
- consistent_snapshot = root_dict .pop ("consistent_snapshot" )
551
+ consistent_snapshot = root_dict .pop ("consistent_snapshot" , None )
552
552
keys = root_dict .pop ("keys" )
553
553
roles = root_dict .pop ("roles" )
554
554
@@ -558,7 +558,7 @@ def from_dict(cls, root_dict: Dict[str, Any]) -> "Root":
558
558
roles [role_name ] = Role .from_dict (role_dict )
559
559
560
560
# All fields left in the root_dict are unrecognized.
561
- return cls (* common_args , consistent_snapshot , keys , roles , root_dict )
561
+ return cls (* common_args , keys , roles , consistent_snapshot , root_dict )
562
562
563
563
def to_dict (self ) -> Dict [str , Any ]:
564
564
"""Returns the dict representation of self."""
@@ -567,10 +567,11 @@ def to_dict(self) -> Dict[str, Any]:
567
567
roles = {}
568
568
for role_name , role in self .roles .items ():
569
569
roles [role_name ] = role .to_dict ()
570
+ if self .consistent_snapshot is not None :
571
+ root_dict ["consistent_snapshot" ] = self .consistent_snapshot
570
572
571
573
root_dict .update (
572
574
{
573
- "consistent_snapshot" : self .consistent_snapshot ,
574
575
"keys" : keys ,
575
576
"roles" : roles ,
576
577
}
0 commit comments