Skip to content

Commit

Permalink
Call mixin-style parent methods on cls/self
Browse files Browse the repository at this point in the history
Call an instance method and a static method that are only defined
in a parent class from child instances using self (instance) and
cls (static) instead of super().

While this doesn't make a practical difference, the new syntax is
probably less confusing to the reader.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
  • Loading branch information
lukpueh committed Mar 10, 2021
1 parent a53d68b commit ef91964
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,15 @@ def __init__(
@classmethod
def from_dict(cls, root_dict: Mapping[str, Any]) -> 'Root':
"""Creates Root object from its dict representation. """
common_args = super()._common_fields_from_dict(root_dict)
common_args = cls._common_fields_from_dict(root_dict)
consistent_snapshot = root_dict.pop('consistent_snapshot')
keys = root_dict.pop('keys')
roles = root_dict.pop('roles')
return cls(*common_args, consistent_snapshot, keys, roles)

def to_dict(self) -> Dict[str, Any]:
"""Returns the dict representation of self. """
root_dict = super()._common_fields_to_dict()
root_dict = self._common_fields_to_dict()
root_dict.update({
'consistent_snapshot': self.consistent_snapshot,
'keys': self.keys,
Expand Down Expand Up @@ -456,13 +456,13 @@ def __init__(
@classmethod
def from_dict(cls, timestamp_dict: Mapping[str, Any]) -> 'Timestamp':
"""Creates Timestamp object from its dict representation. """
common_args = super()._common_fields_from_dict(timestamp_dict)
common_args = cls._common_fields_from_dict(timestamp_dict)
meta = timestamp_dict.pop('meta')
return cls(*common_args, meta)

def to_dict(self) -> Dict[str, Any]:
"""Returns the dict representation of self. """
timestamp_dict = super()._common_fields_to_dict()
timestamp_dict = self._common_fields_to_dict()
timestamp_dict.update({
'meta': self.meta
})
Expand Down Expand Up @@ -515,13 +515,13 @@ def __init__(
@classmethod
def from_dict(cls, snapshot_dict: Mapping[str, Any]) -> 'Snapshot':
"""Creates Snapshot object from its dict representation. """
common_args = super()._common_fields_from_dict(snapshot_dict)
common_args = cls._common_fields_from_dict(snapshot_dict)
meta = snapshot_dict.pop('meta')
return cls(*common_args, meta)

def to_dict(self) -> Dict[str, Any]:
"""Returns the dict representation of self. """
snapshot_dict = super()._common_fields_to_dict()
snapshot_dict = self._common_fields_to_dict()
snapshot_dict.update({
'meta': self.meta
})
Expand Down Expand Up @@ -612,14 +612,14 @@ def __init__(
@classmethod
def from_dict(cls, targets_dict: Mapping[str, Any]) -> 'Targets':
"""Creates Targets object from its dict representation. """
common_args = super()._common_fields_from_dict(targets_dict)
common_args = cls._common_fields_from_dict(targets_dict)
targets = targets_dict.pop('targets')
delegations = targets_dict.pop('delegations')
return cls(*common_args, targets, delegations)

def to_dict(self) -> Dict[str, Any]:
"""Returns the dict representation of self. """
targets_dict = super()._common_fields_to_dict()
targets_dict = self._common_fields_to_dict()
targets_dict.update({
'targets': self.targets,
'delegations': self.delegations,
Expand Down

0 comments on commit ef91964

Please sign in to comment.