Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 16 additions & 176 deletions .basedpyright/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -4021,6 +4021,22 @@
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
"startColumn": 8,
"endColumn": 14,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 45,
"endColumn": 69,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
Expand Down Expand Up @@ -8461,182 +8477,6 @@
"lineCount": 1
}
},
{
"code": "reportUnknownParameterType",
"range": {
"startColumn": 8,
"endColumn": 29,
"lineCount": 1
}
},
{
"code": "reportUnknownParameterType",
"range": {
"startColumn": 30,
"endColumn": 36,
"lineCount": 1
}
},
{
"code": "reportMissingParameterType",
"range": {
"startColumn": 30,
"endColumn": 36,
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
"startColumn": 8,
"endColumn": 13,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 41,
"endColumn": 47,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 23,
"endColumn": 29,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 32,
"endColumn": 38,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 34,
"endColumn": 44,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 20,
"endColumn": 32,
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
"startColumn": 15,
"endColumn": 20,
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
"startColumn": 4,
"endColumn": 17,
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
"startColumn": 4,
"endColumn": 13,
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
"startColumn": 12,
"endColumn": 19,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 12,
"endColumn": 34,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 43,
"endColumn": 56,
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
"startColumn": 45,
"endColumn": 49,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 27,
"endColumn": 31,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 8,
"endColumn": 21,
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
"startColumn": 12,
"endColumn": 16,
"lineCount": 1
}
},
{
"code": "reportUnknownMemberType",
"range": {
"startColumn": 12,
"endColumn": 24,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 15,
"endColumn": 24,
"lineCount": 1
}
},
{
"code": "reportInvalidTypeVarUse",
"range": {
"startColumn": 26,
"endColumn": 31,
"lineCount": 1
}
},
{
"code": "reportUnknownVariableType",
"range": {
Expand Down
2 changes: 2 additions & 0 deletions pytools/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ def __lt__(self, other: _HeapEntry[NodeT]) -> bool:

def compute_topological_order(
graph: GraphT[NodeT],
# should not use CanLt[object] because many types can't compare against
# everything under the sun
key: Callable[[NodeT], optype.CanLt[Any]] | None = None,
) -> list[NodeT]:
"""Compute a topological order of nodes in a directed graph.
Expand Down
13 changes: 7 additions & 6 deletions pytools/test/test_graph_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ def test_prioritized_topological_sort():
from pytools.graph import compute_topological_order
rng = random.Random(0)

def generate_random_graph(nnodes):
graph = {i: set() for i in range(nnodes)}
def generate_random_graph(nnodes: int):
graph: dict[int, set[int]] = {i: set() for i in range(nnodes)}
for i in range(nnodes):
# to avoid cycles only consider edges node_i->node_j where j > i.
for j in range(i+1, nnodes):
Expand All @@ -270,14 +270,15 @@ def generate_random_graph(nnodes):

nnodes = rng.randint(40, 100)
rev_dep_graph = generate_random_graph(nnodes)
dep_graph = {i: set() for i in range(nnodes)}
dep_graph: dict[int, set[int]] = {i: set() for i in range(nnodes)}

for i in range(nnodes):
for rev_dep in rev_dep_graph[i]:
dep_graph[rev_dep].add(i)

keys = [rng.random() for _ in range(nnodes)]
topo_order = compute_topological_order(rev_dep_graph, key=keys.__getitem__)
topo_order = compute_topological_order(
rev_dep_graph, key=keys.__getitem__)

for scheduled_node in topo_order:
nodes_with_no_deps = {node for node, deps in dep_graph.items()
Expand All @@ -303,15 +304,15 @@ def test_as_graphviz_dot():
"B": [],
"C": ["A"]}

from pytools.graph import NodeT, as_graphviz_dot
from pytools.graph import Node, NodeT, as_graphviz_dot

def edge_labels(n1: NodeT, n2: NodeT) -> str:
if n1 == "A" and n2 == "B":
return "foo"

return ""

def node_labels(node: NodeT) -> str:
def node_labels(node: Node) -> str:
if node == "A":
return "foonode"

Expand Down
Loading