use Python 3+ pythonic syntax

parent a936677c
Pipeline #40144 passed with stage
in 56 seconds
......@@ -288,7 +288,7 @@ class MetaDatabase(Database):
servers: Sequence[ResolverID],
create: bool = False
) -> None:
super(MetaDatabase, self).__init__(lmdb_, create)
super().__init__(lmdb_, create)
if create:
self.write_servers(servers)
else:
......
......@@ -93,7 +93,7 @@ class Diff(collections.abc.Mapping):
__delitem__ = None
def __init__(self, qid: QID, mismatches: Mapping[FieldLabel, DataMismatch]) -> None:
super(Diff, self).__init__()
super().__init__()
self.qid = qid
self._mismatches = mismatches
......@@ -159,7 +159,7 @@ class Disagreements(collections.abc.Mapping, JSONDataObject):
}
}
"""
super(Disagreements, self).__init__()
super().__init__()
self._fields = collections.defaultdict(
lambda: collections.defaultdict(set)
) # type: Dict[FieldLabel, Dict[DataMismatch, Set[QID]]]
......@@ -167,7 +167,7 @@ class Disagreements(collections.abc.Mapping, JSONDataObject):
self.restore(_restore_dict)
def restore(self, restore_dict: Mapping[str, Any]) -> None:
super(Disagreements, self).restore(restore_dict)
super().restore(restore_dict)
for field_label, field_data in restore_dict['fields'].items():
for mismatch_data in field_data['mismatches']:
mismatch = DataMismatch(
......@@ -190,7 +190,7 @@ class Disagreements(collections.abc.Mapping, JSONDataObject):
'count': len(mismatches),
'mismatches': mismatches,
}
restore_dict = super(Disagreements, self).save() or {}
restore_dict = super().save() or {}
restore_dict.update({
'count': self.count,
'fields': fields,
......@@ -243,7 +243,7 @@ class DisagreementsCounter(JSONDataObject):
}
def __init__(self, _restore_dict: Mapping[str, int] = None) -> None:
super(DisagreementsCounter, self).__init__()
super().__init__()
self.queries = set() # type: Set[QID]
if _restore_dict is not None:
self.restore(_restore_dict)
......@@ -270,7 +270,7 @@ class Summary(Disagreements):
self.usable_answers = 0
self.upstream_unstable = 0
self.not_reproducible = 0
super(Summary, self).__init__(_restore_dict=_restore_dict)
super().__init__(_restore_dict=_restore_dict)
def add_mismatch(self, field: FieldLabel, mismatch: DataMismatch, qid: QID) -> None:
if qid in self.keys():
......@@ -336,7 +336,7 @@ class ReproCounter(JSONDataObject):
verified: int = 0,
_restore_dict: Optional[Mapping[str, int]] = None
) -> None:
super(ReproCounter, self).__init__()
super().__init__()
self.retries = retries
self.upstream_stable = upstream_stable
self.verified = verified
......@@ -346,7 +346,7 @@ class ReproCounter(JSONDataObject):
def save(self) -> Optional[Dict[str, int]]:
if not self.retries:
return None
return super(ReproCounter, self).save()
return super().save()
def __eq__(self, other) -> bool:
return (
......@@ -357,18 +357,18 @@ class ReproCounter(JSONDataObject):
class ReproData(collections.abc.Mapping, JSONDataObject):
def __init__(self, _restore_dict: Optional[Mapping[str, Any]] = None) -> None:
super(ReproData, self).__init__()
super().__init__()
self._counters = collections.defaultdict(ReproCounter) # type: Dict[QID, ReproCounter]
if _restore_dict is not None:
self.restore(_restore_dict)
def restore(self, restore_dict: Mapping[str, Any]) -> None:
super(ReproData, self).restore(restore_dict)
super().restore(restore_dict)
for qid, counter_data in restore_dict.items():
self._counters[int(qid)] = ReproCounter(_restore_dict=counter_data)
def save(self) -> Optional[Dict[str, Any]]:
restore_dict = super(ReproData, self).save() or {}
restore_dict = super().save() or {}
for qid, counter in self._counters.items():
counter_data = counter.save()
if counter_data is not None:
......@@ -419,7 +419,7 @@ class DiffReport(JSONDataObject): # pylint: disable=too-many-instance-attribute
reprodata: Optional[ReproData] = None,
_restore_dict: Optional[Mapping[str, Any]] = None
) -> None:
super(DiffReport, self).__init__()
super().__init__()
self.start_time = start_time
self.end_time = end_time
self.total_queries = total_queries
......
......@@ -28,7 +28,7 @@ class DataMismatch(Exception):
exp_val = convert_val_type(exp_val)
got_val = convert_val_type(got_val)
super(DataMismatch, self).__init__(exp_val, got_val)
super().__init__(exp_val, got_val)
if exp_val == got_val:
raise RuntimeError("exp_val == got_val ({})".format(exp_val))
self.exp_val = exp_val
......
......@@ -45,7 +45,7 @@ class Stats(JSONDataObject):
samples contain the entire data set of reference values of this parameter.
If no custom threshold is provided, it is calculated automagically.
"""
super(Stats, self).__init__()
super().__init__()
self.samples = samples if samples is not None else []
if threshold is None:
if self.samples:
......@@ -152,7 +152,7 @@ class MismatchStatistics(dict, JSONDataObject):
sample_size: Optional[int] = None,
_restore_dict: Optional[Mapping[str, Any]] = None
) -> None:
super(MismatchStatistics, self).__init__()
super().__init__()
self.total = None
if mismatch_counters_list is not None and sample_size is not None:
samples = collections.defaultdict(list) # type: Dict[str, List[int]]
......@@ -177,14 +177,14 @@ class MismatchStatistics(dict, JSONDataObject):
self.restore(_restore_dict)
def restore(self, restore_dict: Mapping[str, Any]) -> None:
super(MismatchStatistics, self).restore(restore_dict)
super().restore(restore_dict)
for mismatch_key, stats_data in restore_dict.items():
if mismatch_key in self._ATTRIBUTES:
continue # attributes are already loaded
self[mismatch_key] = Stats(_restore_dict=stats_data)
def save(self) -> Dict[str, Any]:
restore_dict = super(MismatchStatistics, self).save() or {}
restore_dict = super().save() or {}
for mismatch_key, stats_data in self.items():
restore_dict[mismatch_key] = stats_data.save()
return restore_dict
......@@ -204,7 +204,7 @@ class FieldStatistics(dict, JSONDataObject):
summaries_list: Optional[Sequence[Summary]] = None,
_restore_dict: Optional[Mapping[str, Any]] = None
) -> None:
super(FieldStatistics, self).__init__()
super().__init__()
if summaries_list is not None:
field_counters_list = [d.get_field_counters() for d in summaries_list]
for field in ALL_FIELDS:
......@@ -215,12 +215,12 @@ class FieldStatistics(dict, JSONDataObject):
self.restore(_restore_dict)
def restore(self, restore_dict: Mapping[str, Any]) -> None:
super(FieldStatistics, self).restore(restore_dict)
super().restore(restore_dict)
for field, field_data in restore_dict.items():
self[field] = MismatchStatistics(_restore_dict=field_data)
def save(self) -> Dict[str, Any]:
restore_dict = super(FieldStatistics, self).save() or {}
restore_dict = super().save() or {}
for field, mismatch_stats in self.items():
restore_dict[field] = mismatch_stats.save()
return restore_dict
......@@ -251,7 +251,7 @@ class SummaryStatistics(JSONDataObject):
summaries: Sequence[Summary] = None,
_restore_dict: Mapping[str, Any] = None
) -> None:
super(SummaryStatistics, self).__init__()
super().__init__()
self.sample_size = None
self.upstream_unstable = None
self.usable_answers = None
......
......@@ -307,7 +307,7 @@ def test_disagreements_counter():
assert len(dc) == 2
dc_restored = DisagreementsCounter(_restore_dict=dc.save())
assert len(dc_restored) == 2
assert dc_restored.queries == set([1, 2])
assert dc_restored.queries == {1, 2}
def test_diff_report():
......@@ -318,7 +318,7 @@ def test_diff_report():
assert report.total_queries == 23122
assert report.total_answers == 23100
assert len(report.other_disagreements) == 3
assert set([7, 8, 9]) == report.other_disagreements.queries
assert {7, 8, 9} == report.other_disagreements.queries
assert len(report.target_disagreements) == 4
report_restored = DiffReport(_restore_dict=report.save())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment