@@ -503,8 +503,8 @@ class Root(Signed):
503503 """A container for the signed part of root metadata.
504504
505505 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.
508508 keys: A dictionary that contains a public key store used to verify
509509 top level roles metadata signatures::
510510
@@ -534,9 +534,9 @@ def __init__(
534534 version : int ,
535535 spec_version : str ,
536536 expires : datetime ,
537- consistent_snapshot : bool ,
538537 keys : Dict [str , Key ],
539538 roles : Dict [str , Role ],
539+ consistent_snapshot : Optional [bool ] = None ,
540540 unrecognized_fields : Optional [Mapping [str , Any ]] = None ,
541541 ) -> None :
542542 super ().__init__ (version , spec_version , expires , unrecognized_fields )
@@ -548,7 +548,7 @@ def __init__(
548548 def from_dict (cls , root_dict : Dict [str , Any ]) -> "Root" :
549549 """Creates Root object from its dict representation."""
550550 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 )
552552 keys = root_dict .pop ("keys" )
553553 roles = root_dict .pop ("roles" )
554554
@@ -558,7 +558,7 @@ def from_dict(cls, root_dict: Dict[str, Any]) -> "Root":
558558 roles [role_name ] = Role .from_dict (role_dict )
559559
560560 # 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 )
562562
563563 def to_dict (self ) -> Dict [str , Any ]:
564564 """Returns the dict representation of self."""
@@ -567,10 +567,11 @@ def to_dict(self) -> Dict[str, Any]:
567567 roles = {}
568568 for role_name , role in self .roles .items ():
569569 roles [role_name ] = role .to_dict ()
570+ if self .consistent_snapshot is not None :
571+ root_dict ["consistent_snapshot" ] = self .consistent_snapshot
570572
571573 root_dict .update (
572574 {
573- "consistent_snapshot" : self .consistent_snapshot ,
574575 "keys" : keys ,
575576 "roles" : roles ,
576577 }
0 commit comments