Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Commit

Permalink
add implementation for set.remove()
Browse files Browse the repository at this point in the history
  • Loading branch information
stummjr committed Nov 20, 2016
1 parent 53dd179 commit ccb1c34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions python/common/org/python/types/Set.java
Expand Up @@ -434,10 +434,14 @@ public org.python.Object pop() {
}

@org.python.Method(
__doc__ = ""
__doc__ = "Remove an element from a set; it must be a member.\n\nIf the element is not a member, raise a KeyError.",
args = {"item"}
)
public org.python.Object remove(org.python.Object other) {
throw new org.python.exceptions.NotImplementedError("remove() has not been implemented.");
public org.python.Object remove(org.python.Object item) {
if (!this.value.remove(item)) {
throw new org.python.exceptions.KeyError(item);
}
return org.python.types.NoneType.NONE;
}

@org.python.Method(
Expand Down
8 changes: 8 additions & 0 deletions tests/datatypes/test_set.py
Expand Up @@ -108,6 +108,14 @@ def test_intersection(self):
print(z)
""")

def test_remove(self):
self.assertCodeExecution("""
x = {1, 2, 3}
x.remove(1)
x.remove(4)
print(x)
""")


class UnarySetOperationTests(UnaryOperationTestCase, TranspileTestCase):
data_type = 'set'
Expand Down

0 comments on commit ccb1c34

Please sign in to comment.