1
0
Fork 0

Add from __future__ import annotations

This makes the code work on Python versions 3.7 and 3.8.
This commit is contained in:
Joris van Rantwijk 2024-07-09 19:25:55 +02:00
parent 147640329f
commit d3475834ab
2 changed files with 14 additions and 13 deletions

View File

@ -389,12 +389,11 @@ class Blossom:
# "tree_blossoms" is the set of all top-level blossoms that belong
# to the same alternating tree. The same set instance is shared by
# all top-level blossoms in the tree.
self.tree_blossoms: "Optional[set[Blossom]]" = None
self.tree_blossoms: Optional[set[Blossom]] = None
# Each top-level blossom maintains a union-find datastructure
# containing all vertices in the blossom.
self.vertex_set: "UnionFindQueue[Blossom, int]"
self.vertex_set = UnionFindQueue(self)
self.vertex_set: UnionFindQueue[Blossom, int] = UnionFindQueue(self)
# If this is a top-level unlabeled blossom with an edge to an
# S-blossom, "delta2_node" is the corresponding node in the delta2

View File

@ -1,5 +1,7 @@
"""Data structures for matching."""
from __future__ import annotations
from typing import Generic, Optional, TypeVar
@ -38,7 +40,7 @@ class UnionFindQueue(Generic[_NameT, _ElemT]):
"parent", "left", "right")
def __init__(self,
owner: "UnionFindQueue[_NameT2, _ElemT2]",
owner: UnionFindQueue[_NameT2, _ElemT2],
data: _ElemT2,
prio: float
) -> None:
@ -47,14 +49,14 @@ class UnionFindQueue(Generic[_NameT, _ElemT]):
This method should not be called directly.
Instead, call UnionFindQueue.insert().
"""
self.owner: "Optional[UnionFindQueue[_NameT2, _ElemT2]]" = owner
self.owner: Optional[UnionFindQueue[_NameT2, _ElemT2]] = owner
self.data = data
self.prio = prio
self.min_node = self
self.height = 1
self.parent: "Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]"
self.left: "Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]"
self.right: "Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]"
self.parent: Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]
self.left: Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]
self.right: Optional[UnionFindQueue.Node[_NameT2, _ElemT2]]
self.parent = None
self.left = None
self.right = None
@ -98,9 +100,9 @@ class UnionFindQueue(Generic[_NameT, _ElemT]):
name: Name to assign to the new queue.
"""
self.name = name
self.tree: "Optional[UnionFindQueue.Node[_NameT, _ElemT]]" = None
self.sub_queues: "list[UnionFindQueue[_NameT, _ElemT]]" = []
self.split_nodes: "list[UnionFindQueue.Node[_NameT, _ElemT]]" = []
self.tree: Optional[UnionFindQueue.Node[_NameT, _ElemT]] = None
self.sub_queues: list[UnionFindQueue[_NameT, _ElemT]] = []
self.split_nodes: list[UnionFindQueue.Node[_NameT, _ElemT]] = []
def clear(self) -> None:
"""Remove all elements from the queue.
@ -165,7 +167,7 @@ class UnionFindQueue(Generic[_NameT, _ElemT]):
return node.min_node.data
def merge(self,
sub_queues: "list[UnionFindQueue[_NameT, _ElemT]]"
sub_queues: list[UnionFindQueue[_NameT, _ElemT]]
) -> None:
"""Merge the specified queues.
@ -712,7 +714,7 @@ class PriorityQueue(Generic[_ElemT]):
def __init__(self) -> None:
"""Initialize an empty queue."""
self.heap: "list[PriorityQueue.Node[_ElemT]]" = []
self.heap: list[PriorityQueue.Node[_ElemT]] = []
def clear(self) -> None:
"""Remove all elements from the queue.