Skip to content

Commit ef91964

Browse files
committed
Call mixin-style parent methods on cls/self
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 <[email protected]>
1 parent a53d68b commit ef91964

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

tuf/api/metadata.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,15 @@ def __init__(
391391
@classmethod
392392
def from_dict(cls, root_dict: Mapping[str, Any]) -> 'Root':
393393
"""Creates Root object from its dict representation. """
394-
common_args = super()._common_fields_from_dict(root_dict)
394+
common_args = cls._common_fields_from_dict(root_dict)
395395
consistent_snapshot = root_dict.pop('consistent_snapshot')
396396
keys = root_dict.pop('keys')
397397
roles = root_dict.pop('roles')
398398
return cls(*common_args, consistent_snapshot, keys, roles)
399399

400400
def to_dict(self) -> Dict[str, Any]:
401401
"""Returns the dict representation of self. """
402-
root_dict = super()._common_fields_to_dict()
402+
root_dict = self._common_fields_to_dict()
403403
root_dict.update({
404404
'consistent_snapshot': self.consistent_snapshot,
405405
'keys': self.keys,
@@ -456,13 +456,13 @@ def __init__(
456456
@classmethod
457457
def from_dict(cls, timestamp_dict: Mapping[str, Any]) -> 'Timestamp':
458458
"""Creates Timestamp object from its dict representation. """
459-
common_args = super()._common_fields_from_dict(timestamp_dict)
459+
common_args = cls._common_fields_from_dict(timestamp_dict)
460460
meta = timestamp_dict.pop('meta')
461461
return cls(*common_args, meta)
462462

463463
def to_dict(self) -> Dict[str, Any]:
464464
"""Returns the dict representation of self. """
465-
timestamp_dict = super()._common_fields_to_dict()
465+
timestamp_dict = self._common_fields_to_dict()
466466
timestamp_dict.update({
467467
'meta': self.meta
468468
})
@@ -515,13 +515,13 @@ def __init__(
515515
@classmethod
516516
def from_dict(cls, snapshot_dict: Mapping[str, Any]) -> 'Snapshot':
517517
"""Creates Snapshot object from its dict representation. """
518-
common_args = super()._common_fields_from_dict(snapshot_dict)
518+
common_args = cls._common_fields_from_dict(snapshot_dict)
519519
meta = snapshot_dict.pop('meta')
520520
return cls(*common_args, meta)
521521

522522
def to_dict(self) -> Dict[str, Any]:
523523
"""Returns the dict representation of self. """
524-
snapshot_dict = super()._common_fields_to_dict()
524+
snapshot_dict = self._common_fields_to_dict()
525525
snapshot_dict.update({
526526
'meta': self.meta
527527
})
@@ -612,14 +612,14 @@ def __init__(
612612
@classmethod
613613
def from_dict(cls, targets_dict: Mapping[str, Any]) -> 'Targets':
614614
"""Creates Targets object from its dict representation. """
615-
common_args = super()._common_fields_from_dict(targets_dict)
615+
common_args = cls._common_fields_from_dict(targets_dict)
616616
targets = targets_dict.pop('targets')
617617
delegations = targets_dict.pop('delegations')
618618
return cls(*common_args, targets, delegations)
619619

620620
def to_dict(self) -> Dict[str, Any]:
621621
"""Returns the dict representation of self. """
622-
targets_dict = super()._common_fields_to_dict()
622+
targets_dict = self._common_fields_to_dict()
623623
targets_dict.update({
624624
'targets': self.targets,
625625
'delegations': self.delegations,

0 commit comments

Comments
 (0)