Various ruff fixes (#12821)

This commit is contained in:
Christian Clauss
2025-07-06 00:35:29 +02:00
committed by GitHub
parent 7665ba5e25
commit cd3c3c3130
25 changed files with 69 additions and 70 deletions

View File

@ -21,14 +21,14 @@ from __future__ import annotations
import random
import unittest
from pprint import pformat
from typing import Generic, TypeVar
from typing import TypeVar
import pytest
T = TypeVar("T")
class GraphAdjacencyList(Generic[T]):
class GraphAdjacencyList[T]:
def __init__(
self, vertices: list[T], edges: list[list[T]], directed: bool = True
) -> None:

View File

@ -21,14 +21,14 @@ from __future__ import annotations
import random
import unittest
from pprint import pformat
from typing import Generic, TypeVar
from typing import TypeVar
import pytest
T = TypeVar("T")
class GraphAdjacencyMatrix(Generic[T]):
class GraphAdjacencyMatrix[T]:
def __init__(
self, vertices: list[T], edges: list[list[T]], directed: bool = True
) -> None:

View File

@ -6,12 +6,12 @@
from __future__ import annotations
from pprint import pformat
from typing import Generic, TypeVar
from typing import TypeVar
T = TypeVar("T")
class GraphAdjacencyList(Generic[T]):
class GraphAdjacencyList[T]:
"""
Adjacency List type Graph Data Structure that accounts for directed and undirected
Graphs. Initialize graph object indicating whether it's directed or undirected.

View File

@ -1,11 +1,11 @@
from __future__ import annotations
from typing import Generic, TypeVar
from typing import TypeVar
T = TypeVar("T")
class DisjointSetTreeNode(Generic[T]):
class DisjointSetTreeNode[T]:
# Disjoint Set Node to store the parent and rank
def __init__(self, data: T) -> None:
self.data = data
@ -13,7 +13,7 @@ class DisjointSetTreeNode(Generic[T]):
self.rank = 0
class DisjointSetTree(Generic[T]):
class DisjointSetTree[T]:
# Disjoint Set DataStructure
def __init__(self) -> None:
# map from node name to the node object
@ -46,7 +46,7 @@ class DisjointSetTree(Generic[T]):
self.link(self.find_set(data1), self.find_set(data2))
class GraphUndirectedWeighted(Generic[T]):
class GraphUndirectedWeighted[T]:
def __init__(self) -> None:
# connections: map from the node to the neighbouring nodes (with weights)
self.connections: dict[T, dict[T, int]] = {}

View File

@ -10,7 +10,7 @@ connection from the tree to another vertex.
from __future__ import annotations
from sys import maxsize
from typing import Generic, TypeVar
from typing import TypeVar
T = TypeVar("T")
@ -47,7 +47,7 @@ def get_child_right_position(position: int) -> int:
return (2 * position) + 2
class MinPriorityQueue(Generic[T]):
class MinPriorityQueue[T]:
"""
Minimum Priority Queue Class
@ -184,7 +184,7 @@ class MinPriorityQueue(Generic[T]):
self.position_map[node2_elem] = node1_pos
class GraphUndirectedWeighted(Generic[T]):
class GraphUndirectedWeighted[T]:
"""
Graph Undirected Weighted Class
@ -217,7 +217,7 @@ class GraphUndirectedWeighted(Generic[T]):
self.connections[node2][node1] = weight
def prims_algo(
def prims_algo[T](
graph: GraphUndirectedWeighted[T],
) -> tuple[dict[T, int], dict[T, T | None]]:
"""