From 771d989670805593049d7c566ca8b3353b262d4c Mon Sep 17 00:00:00 2001 From: Jerome Kelleher Date: Thu, 25 Jul 2024 14:36:17 +0100 Subject: [PATCH] Update the class definitions --- algorithms.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/algorithms.py b/algorithms.py index d83faf5b1..d5fcbb478 100644 --- a/algorithms.py +++ b/algorithms.py @@ -1,6 +1,8 @@ """ Python version of the simulation algorithm. """ +from __future__ import annotations + import argparse import dataclasses import heapq @@ -111,6 +113,9 @@ def find(self, v): return j + 1 +# Once we drop support for 3.9 we can use slots=True to prevent +# writing extra attrs. +@dataclasses.dataclass # (slots=True) class Segment: """ A class representing a single segment. Each segment has a left @@ -118,16 +123,15 @@ class Segment: next, giving the next in the chain. """ - def __init__(self, index): - self.left = None - self.right = None - self.node = None - self.prev = None - self.next = None - self.index = index - self.population = None - self.label = 0 - self.lineage = None + index: int + left: float = 0 + right: float = 0 + node: int = -1 + prev: Segment = None + next: Segment = None # noqa: A003 + lineage: Lineage = None + population: int = -1 + label: int = 0 def __repr__(self): return repr((self.left, self.right, self.node)) @@ -1070,7 +1074,6 @@ def alloc_segment( prev=None, next=None, # noqa: A002 label=0, - hull=None, ): """ Pops a new segment off the stack and sets its properties. @@ -1083,7 +1086,6 @@ def alloc_segment( s.next = next s.prev = prev s.label = label - s.hull = hull return s def alloc_lineage(self, head):