Skip to content

Commit

Permalink
Backport graphlib to work on Python 3.6, refs #878
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Nov 16, 2021
1 parent f4c5f58 commit 8f757da
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions datasette/utils/vendored_graphlib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Vendored from https://raw.githubusercontent.com/python/cpython/3.10/Lib/graphlib.py
# Modified to work on Python 3.6 (I removed := operator)
# License: https://github.com/python/cpython/blob/main/LICENSE

__all__ = ["TopologicalSorter", "CycleError"]
Expand Down Expand Up @@ -53,7 +54,8 @@ def __init__(self, graph=None):
self.add(node, *predecessors)

def _get_nodeinfo(self, node):
if (result := self._node2info.get(node)) is None:
result = self._node2info.get(node)
if result is None:
self._node2info[node] = result = _NodeInfo(node)
return result

Expand Down Expand Up @@ -169,7 +171,8 @@ def done(self, *nodes):
for node in nodes:

# Check if we know about this node (it was added previously using add()
if (nodeinfo := n2i.get(node)) is None:
nodeinfo = n2i.get(node)
if nodeinfo is None:
raise ValueError(f"node {node!r} was not added using add()")

# If the node has not being returned (marked as ready) previously, inform the user.
Expand Down

0 comments on commit 8f757da

Please sign in to comment.