diff --git a/python/common/org/python/types/Set.java b/python/common/org/python/types/Set.java index 61b86f315d..f539495bc2 100644 --- a/python/common/org/python/types/Set.java +++ b/python/common/org/python/types/Set.java @@ -275,12 +275,20 @@ public org.python.Object __mul__(org.python.Object other) { // throw new org.python.exceptions.NotImplementedError("__sub__() has not been implemented"); // } - // @org.python.Method( - // __doc__ = "" - // ) - // public org.python.Object __and__(org.python.Object other) { - // throw new org.python.exceptions.NotImplementedError("__and__() has not been implemented"); - // } + @org.python.Method( + __doc__ = "" + ) + public org.python.Object __and__(org.python.Object other) { + java.util.Set set = ((org.python.types.Set) this.copy()).value; + if (other instanceof org.python.types.Set) { + set.retainAll(((org.python.types.Set) other).value); + return new org.python.types.Set(set); + } else if (other instanceof org.python.types.FrozenSet) { + set.retainAll(((org.python.types.FrozenSet) other).value); + return new org.python.types.Set(set); + } + throw new org.python.exceptions.TypeError("unsupported operand type(s) for &: '" + this.typeName() + "' and '" + other.typeName() + "'"); + } // @org.python.Method( // __doc__ = "" diff --git a/tests/datatypes/test_set.py b/tests/datatypes/test_set.py index 78792cf14f..55f6ef0aa2 100644 --- a/tests/datatypes/test_set.py +++ b/tests/datatypes/test_set.py @@ -231,8 +231,6 @@ class BinarySetOperationTests(BinaryOperationTestCase, TranspileTestCase): 'test_add_frozenset', 'test_and_class', - 'test_and_frozenset', - 'test_and_set', 'test_direct_eq_bytes', 'test_direct_eq_set',