@@ -817,7 +817,7 @@ def __init__(
817
817
spec_version : str ,
818
818
expires : datetime ,
819
819
targets : Mapping [str , Any ],
820
- delegations : Mapping [str , Any ],
820
+ delegations : Optional [ Mapping [str , Any ]] = None ,
821
821
unrecognized_fields : Optional [Mapping [str , Any ]] = None ,
822
822
) -> None :
823
823
super ().__init__ (
@@ -832,19 +832,16 @@ def from_dict(cls, targets_dict: Mapping[str, Any]) -> "Targets":
832
832
"""Creates Targets object from its dict representation."""
833
833
common_args = cls ._common_fields_from_dict (targets_dict )
834
834
targets = targets_dict .pop ("targets" )
835
- delegations = targets_dict .pop ("delegations" )
835
+ delegations = targets_dict .pop ("delegations" , None )
836
836
# All fields left in the targets_dict are unrecognized.
837
837
return cls (* common_args , targets , delegations , targets_dict )
838
838
839
839
def to_dict (self ) -> Dict [str , Any ]:
840
840
"""Returns the dict representation of self."""
841
841
targets_dict = self ._common_fields_to_dict ()
842
- targets_dict .update (
843
- {
844
- "targets" : self .targets ,
845
- "delegations" : self .delegations ,
846
- }
847
- )
842
+ targets_dict ["targets" ] = self .targets
843
+ if self .delegations :
844
+ targets_dict ["delegations" ] = self .delegations
848
845
return targets_dict
849
846
850
847
# Modification.
0 commit comments