Skip to content

Commit 5ecd06d

Browse files
author
Zhen Li
committed
Rename identity to id
1 parent e6d031b commit 5ecd06d

File tree

4 files changed

+50
-51
lines changed

4 files changed

+50
-51
lines changed

neo4j/v1/types.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
of these classes.
2626
"""
2727

28-
2928
from .packstream import Structure
3029

3130

3231
class Entity(object):
3332
""" Base class for Node and Relationship.
3433
"""
35-
identity = None
34+
id = None
3635
properties = None
3736

3837
def __init__(self, properties=None, **kwproperties):
@@ -41,15 +40,15 @@ def __init__(self, properties=None, **kwproperties):
4140

4241
def __eq__(self, other):
4342
try:
44-
return self.identity == other.identity
43+
return self.id == other.id
4544
except AttributeError:
4645
return False
4746

4847
def __ne__(self, other):
4948
return not self.__eq__(other)
5049

5150
def __hash__(self):
52-
return hash(self.identity)
51+
return hash(self.id)
5352

5453
def __len__(self):
5554
return len(self.properties)
@@ -82,18 +81,18 @@ class Node(Entity):
8281
labels = None
8382

8483
@classmethod
85-
def hydrate(cls, identity, labels, properties=None):
84+
def hydrate(cls, id_, labels, properties=None):
8685
inst = cls(labels, properties)
87-
inst.identity = identity
86+
inst.id = id_
8887
return inst
8988

9089
def __init__(self, labels=None, properties=None, **kwproperties):
9190
super(Node, self).__init__(properties, **kwproperties)
9291
self.labels = set(labels or set())
9392

9493
def __repr__(self):
95-
return "<Node identity=%r labels=%r properties=%r>" % \
96-
(self.identity, self.labels, self.properties)
94+
return "<Node id=%r labels=%r properties=%r>" % \
95+
(self.id, self.labels, self.properties)
9796

9897

9998
class BaseRelationship(Entity):
@@ -113,9 +112,9 @@ class Relationship(BaseRelationship):
113112
end = None
114113

115114
@classmethod
116-
def hydrate(cls, identity, start, end, type, properties=None):
115+
def hydrate(cls, id_, start, end, type, properties=None):
117116
inst = cls(start, end, type, properties)
118-
inst.identity = identity
117+
inst.id = id_
119118
return inst
120119

121120
def __init__(self, start, end, type, properties=None, **kwproperties):
@@ -126,12 +125,12 @@ def __init__(self, start, end, type, properties=None, **kwproperties):
126125
self.end = end
127126

128127
def __repr__(self):
129-
return "<Relationship identity=%r start=%r end=%r type=%r properties=%r>" % \
130-
(self.identity, self.start, self.end, self.type, self.properties)
128+
return "<Relationship id=%r start=%r end=%r type=%r properties=%r>" % \
129+
(self.id, self.start, self.end, self.type, self.properties)
131130

132131
def unbind(self):
133132
inst = UnboundRelationship(self.type, self.properties)
134-
inst.identity = self.identity
133+
inst.id = self.id
135134
return inst
136135

137136

@@ -140,21 +139,21 @@ class UnboundRelationship(BaseRelationship):
140139
"""
141140

142141
@classmethod
143-
def hydrate(cls, identity, type, properties=None):
142+
def hydrate(cls, id_, type, properties=None):
144143
inst = cls(type, properties)
145-
inst.identity = identity
144+
inst.id = id_
146145
return inst
147146

148147
def __init__(self, type, properties=None, **kwproperties):
149148
super(UnboundRelationship, self).__init__(type, properties, **kwproperties)
150149

151150
def __repr__(self):
152-
return "<UnboundRelationship identity=%r type=%r properties=%r>" % \
153-
(self.identity, self.type, self.properties)
151+
return "<UnboundRelationship id=%r type=%r properties=%r>" % \
152+
(self.id, self.type, self.properties)
154153

155154
def bind(self, start, end):
156155
inst = Relationship(start, end, self.type, self.properties)
157-
inst.identity = self.identity
156+
inst.id = self.id
158157
return inst
159158

160159

@@ -174,9 +173,9 @@ def hydrate(cls, nodes, rels, sequence):
174173
assert rel_index != 0
175174
next_node = nodes[sequence[2 * i + 1]]
176175
if rel_index > 0:
177-
entities.append(rels[rel_index - 1].bind(last_node.identity, next_node.identity))
176+
entities.append(rels[rel_index - 1].bind(last_node.id, next_node.id))
178177
else:
179-
entities.append(rels[-rel_index - 1].bind(next_node.identity, last_node.identity))
178+
entities.append(rels[-rel_index - 1].bind(next_node.id, last_node.id))
180179
entities.append(next_node)
181180
last_node = next_node
182181
return cls(*entities)
@@ -187,7 +186,7 @@ def __init__(self, start_node, *rels_and_nodes):
187186

188187
def __repr__(self):
189188
return "<Path start=%r end=%r size=%s>" % \
190-
(self.start.identity, self.end.identity, len(self))
189+
(self.start.id, self.end.id, len(self))
191190

192191
def __eq__(self, other):
193192
try:

test/tck/resultparser.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,19 @@ def get_path(string_path):
181181
string_path = string_path[1:-1]
182182
n, string_path = get_node(string_path)
183183
list_of_nodes_and_rel = [n]
184-
n.identity = ++id
184+
n.id = ++id
185185
while string_path != '':
186186
r, string_path, point_up = get_relationship(string_path)
187187
n, string_path = get_node(string_path)
188-
n.identity = ++id
188+
n.id = ++id
189189
if point_up:
190-
r.start = list_of_nodes_and_rel[-1].identity
191-
r.end = n.identity
192-
r.identity = 0
190+
r.start = list_of_nodes_and_rel[-1].id
191+
r.end = n.id
192+
r.id = 0
193193
else:
194-
r.start = n.identity
195-
r.end = list_of_nodes_and_rel[-1].identity
196-
r.identity = 0
194+
r.start = n.id
195+
r.end = list_of_nodes_and_rel[-1].id
196+
r.id = 0
197197
list_of_nodes_and_rel.append(r)
198198
list_of_nodes_and_rel.append(n)
199199
path = Path(list_of_nodes_and_rel[0], *list_of_nodes_and_rel[1:])

test/tck/tck_util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ def create_node(self, entity):
114114

115115
def create_path(self, entity):
116116
content = {}
117-
prev_id = entity.start.identity
117+
prev_id = entity.start.id
118118
p = []
119119
for i, rel in enumerate(list(entity)):
120120
n = entity.nodes[i + 1]
121-
current_id = n.identity
121+
current_id = n.id
122122
if rel.start == prev_id and rel.end == current_id:
123123
rel.start = i
124124
rel.end = i + 1

test/test_types.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ def test_null_properties(self):
5757

5858
def test_node_equality(self):
5959
node_1 = Node()
60-
node_1.identity = 1234
60+
node_1.id = 1234
6161
node_2 = Node()
62-
node_2.identity = 1234
62+
node_2.id = 1234
6363
node_3 = Node()
64-
node_3.identity = 5678
64+
node_3.id = 5678
6565
assert node_1 == node_2
6666
assert node_1 != node_3
6767
assert node_1 != "this is not a node"
6868

6969
def test_node_hashing(self):
7070
node_1 = Node()
71-
node_1.identity = 1234
71+
node_1.id = 1234
7272
node_2 = Node()
73-
node_2.identity = 1234
73+
node_2.id = 1234
7474
node_3 = Node()
75-
node_3.identity = 5678
75+
node_3.id = 5678
7676
assert hash(node_1) == hash(node_2)
7777
assert hash(node_1) != hash(node_3)
7878

@@ -82,10 +82,10 @@ class RelationshipTestCase(TestCase):
8282
def test_can_create_relationship(self):
8383
alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33})
8484
bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44})
85-
alice_knows_bob = Relationship(alice.identity, bob.identity, "KNOWS", {"since": 1999})
86-
assert alice_knows_bob.start == alice.identity
85+
alice_knows_bob = Relationship(alice.id, bob.id, "KNOWS", {"since": 1999})
86+
assert alice_knows_bob.start == alice.id
8787
assert alice_knows_bob.type == "KNOWS"
88-
assert alice_knows_bob.end == bob.identity
88+
assert alice_knows_bob.end == bob.id
8989
assert set(alice_knows_bob.keys()) == {"since"}
9090
assert set(alice_knows_bob.values()) == {1999}
9191
assert set(alice_knows_bob.items()) == {("since", 1999)}
@@ -111,8 +111,8 @@ def test_can_create_path(self):
111111
alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33})
112112
bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44})
113113
carol = Node.hydrate(3, {"Person"}, {"name": "Carol", "age": 55})
114-
alice_knows_bob = Relationship(alice.identity, bob.identity, "KNOWS", {"since": 1999})
115-
carol_dislikes_bob = Relationship(carol.identity, bob.identity, "DISLIKES")
114+
alice_knows_bob = Relationship(alice.id, bob.id, "KNOWS", {"since": 1999})
115+
carol_dislikes_bob = Relationship(carol.id, bob.id, "DISLIKES")
116116
path = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
117117
assert path.start == alice
118118
assert path.end == carol
@@ -125,8 +125,8 @@ def test_can_hydrate_path(self):
125125
alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33})
126126
bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44})
127127
carol = Node.hydrate(3, {"Person"}, {"name": "Carol", "age": 55})
128-
alice_knows_bob = Relationship(alice.identity, bob.identity, "KNOWS", {"since": 1999})
129-
carol_dislikes_bob = Relationship(carol.identity, bob.identity, "DISLIKES")
128+
alice_knows_bob = Relationship(alice.id, bob.id, "KNOWS", {"since": 1999})
129+
carol_dislikes_bob = Relationship(carol.id, bob.id, "DISLIKES")
130130
path = Path.hydrate([alice, bob, carol],
131131
[alice_knows_bob.unbind(), carol_dislikes_bob.unbind()],
132132
[1, 1, -2, 2])
@@ -141,8 +141,8 @@ def test_path_equality(self):
141141
alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33})
142142
bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44})
143143
carol = Node.hydrate(3, {"Person"}, {"name": "Carol", "age": 55})
144-
alice_knows_bob = Relationship(alice.identity, bob.identity, "KNOWS", {"since": 1999})
145-
carol_dislikes_bob = Relationship(carol.identity, bob.identity, "DISLIKES")
144+
alice_knows_bob = Relationship(alice.id, bob.id, "KNOWS", {"since": 1999})
145+
carol_dislikes_bob = Relationship(carol.id, bob.id, "DISLIKES")
146146
path_1 = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
147147
path_2 = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
148148
assert path_1 == path_2
@@ -152,8 +152,8 @@ def test_path_hashing(self):
152152
alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33})
153153
bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44})
154154
carol = Node.hydrate(3, {"Person"}, {"name": "Carol", "age": 55})
155-
alice_knows_bob = Relationship(alice.identity, bob.identity, "KNOWS", {"since": 1999})
156-
carol_dislikes_bob = Relationship(carol.identity, bob.identity, "DISLIKES")
155+
alice_knows_bob = Relationship(alice.id, bob.id, "KNOWS", {"since": 1999})
156+
carol_dislikes_bob = Relationship(carol.id, bob.id, "DISLIKES")
157157
path_1 = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
158158
path_2 = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
159159
assert hash(path_1) == hash(path_2)
@@ -167,7 +167,7 @@ def test_can_hydrate_node_structure(self):
167167
struct.append(["Person"])
168168
struct.append({"name": "Alice"})
169169
alice = hydrated(struct)
170-
assert alice.identity == 123
170+
assert alice.id == 123
171171
assert alice.labels == {"Person"}
172172
assert set(alice.keys()) == {"name"}
173173
assert alice.get("name") == "Alice"
@@ -186,7 +186,7 @@ def test_can_hydrate_in_list(self):
186186
alice_in_list = hydrated([struct])
187187
assert isinstance(alice_in_list, list)
188188
alice, = alice_in_list
189-
assert alice.identity == 123
189+
assert alice.id == 123
190190
assert alice.labels == {"Person"}
191191
assert set(alice.keys()) == {"name"}
192192
assert alice.get("name") == "Alice"
@@ -199,7 +199,7 @@ def test_can_hydrate_in_dict(self):
199199
alice_in_dict = hydrated({"foo": struct})
200200
assert isinstance(alice_in_dict, dict)
201201
alice = alice_in_dict["foo"]
202-
assert alice.identity == 123
202+
assert alice.id == 123
203203
assert alice.labels == {"Person"}
204204
assert set(alice.keys()) == {"name"}
205205
assert alice.get("name") == "Alice"

0 commit comments

Comments
 (0)