@@ -29,17 +29,26 @@ def __init__(self, graph, *, first=None, last=None):
29
29
def __rshift__ (self , other ):
30
30
""" Self >> Other """
31
31
32
+ # Allow to concatenate cursors.
33
+ if isinstance (other , GraphCursor ):
34
+ chain = self .graph .add_chain (_input = self .last , _output = other .first )
35
+ return GraphCursor (chain .graph , first = self .first , last = other .last )
36
+
37
+ # If we get a partial graph, or anything with a node list, use that.
32
38
nodes = other .nodes if hasattr (other , "nodes" ) else [other ]
33
39
40
+ # Sometimes, we use ellipsis to show "pseudo-code". This is ok, but can't be executed.
34
41
if ... in nodes :
35
42
raise NotImplementedError (
36
43
"Expected something looking like a node, but got an Ellipsis (...). Did you forget to complete the graph?"
37
44
)
38
45
46
+ # If there are nodes to add, create a new cursor after the chain is added to the graph.
39
47
if len (nodes ):
40
48
chain = self .graph .add_chain (* nodes , _input = self .last , use_existing_nodes = True )
41
49
return GraphCursor (chain .graph , first = self .first , last = chain .output )
42
50
51
+ # If we add nothing, then nothing changed.
43
52
return self
44
53
45
54
def __enter__ (self ):
@@ -49,7 +58,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):
49
58
return None
50
59
51
60
def __eq__ (self , other ):
52
- return self .graph == other .graph and self .first == other .first and self .last == other .last
61
+ try :
62
+ return self .graph == other .graph and self .first == other .first and self .last == other .last
63
+ except AttributeError :
64
+ return False
53
65
54
66
55
67
class PartialGraph :
0 commit comments