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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
[[release-4-0-0]]
=== TinkerPop 4.0.0 (NOT OFFICIALLY RELEASED YET)

* Added `__contains__` and `keys()` to `Element` in `gremlin-python`.
* Added `subgraph()` support for `gremlin-python` so that results are stored in a detached `Graph` object.
* Modified grammar to make `discard()` usage more consistent as a filter step where it can now be used to chain additional traversal steps and be used anonymously.
* Removed `Meta` field from `ResponseResult` struct in `gremlin-go`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ def __getitem__(self, key):
return p.value
raise KeyError(key)

def __contains__(self, key):
for p in self.properties:
if p.key == key:
return True
return False

def keys(self):
return set(p.key for p in self.properties)

def values(self, *property_keys):
if len(property_keys) == 0:
return [p.value for p in self.properties]
Expand Down
21 changes: 21 additions & 0 deletions gremlin-python/src/main/python/tests/unit/structure/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,24 @@ def test_element_value_values(self):
assert vp["acl"] == "public"
assert vp.values("acl") == ["public"]
assert vp.values() == ["public"]

def test_element_contains_and_keys(self):
v = Vertex(1, "person", [VertexProperty(10, "name", "marko", Vertex(1)),
VertexProperty(11, "age", 29, Vertex(1))])
assert "name" in v
assert "age" in v
assert "nonexistent" not in v
assert v.keys() == {"name", "age"}

e = Edge(2, Vertex(1), "knows", Vertex(3), [Property("weight", 0.5, None)])
assert "weight" in e
assert "missing" not in e
assert e.keys() == {"weight"}

empty_v = Vertex(99)
assert "anything" not in empty_v
assert empty_v.keys() == set()

# supports the pattern: vertex[key] if key in vertex else None
assert v["name"] if "name" in v else None == "marko"
assert v["missing"] if "missing" in v else None is None
Loading