43
43
from sage .structure .element import Element
44
44
from sage .structure .parent import Parent , Set_generic
45
45
from sage .structure .richcmp import richcmp_method , richcmp , rich_to_bool
46
+ from sage .misc .classcall_metaclass import ClasscallMetaclass
46
47
47
48
from sage .categories .sets_cat import Sets
48
49
from sage .categories .enumerated_sets import EnumeratedSets
@@ -229,7 +230,7 @@ def union(self, X):
229
230
sage: sorted(Set(GF(7)) + Set(GF(3)), key=int)
230
231
[0, 0, 1, 1, 2, 2, 3, 4, 5, 6]
231
232
"""
232
- if isinstance (X , Set_generic ):
233
+ if isinstance (X , ( Set_generic , Set_base ) ):
233
234
if self is X :
234
235
return self
235
236
return Set_object_union (self , X )
@@ -258,7 +259,7 @@ def intersection(self, X):
258
259
sage: X
259
260
{}
260
261
"""
261
- if isinstance (X , Set_generic ):
262
+ if isinstance (X , ( Set_generic , Set_base ) ):
262
263
if self is X :
263
264
return self
264
265
return Set_object_intersection (self , X )
@@ -287,7 +288,7 @@ def difference(self, X):
287
288
sage: X
288
289
{0, 1, 2, b, b + 1, b + 2, 2*b, 2*b + 1, 2*b + 2}
289
290
"""
290
- if isinstance (X , Set_generic ):
291
+ if isinstance (X , ( Set_generic , Set_base ) ):
291
292
if self is X :
292
293
return Set ([])
293
294
return Set_object_difference (self , X )
@@ -303,7 +304,7 @@ def symmetric_difference(self, X):
303
304
sage: X
304
305
{1, 2, 4}
305
306
"""
306
- if isinstance (X , Set_generic ):
307
+ if isinstance (X , ( Set_generic , Set_base ) ):
307
308
if self is X :
308
309
return Set ([])
309
310
return Set_object_symmetric_difference (self , X )
@@ -1179,7 +1180,7 @@ def symmetric_difference(self, other):
1179
1180
return Set_object_enumerated (self .set ().symmetric_difference (other .set ()))
1180
1181
1181
1182
1182
- class Set_object_binary (Set_object ):
1183
+ class Set_object_binary (Set_object , metaclass = ClasscallMetaclass ):
1183
1184
r"""
1184
1185
An abstract common base class for sets defined by a binary operation (ex.
1185
1186
:class:`Set_object_union`, :class:`Set_object_intersection`,
@@ -1200,9 +1201,32 @@ class Set_object_binary(Set_object):
1200
1201
sage: Y = Set(ZZ)
1201
1202
sage: from sage.sets.set import Set_object_binary
1202
1203
sage: S = Set_object_binary(X, Y, "union", "\\cup"); S
1203
- Set-theoretic union of Set of elements of Vector space of dimension 2
1204
- over Rational Field and Set of elements of Integer Ring
1204
+ Set-theoretic union of
1205
+ Set of elements of Vector space of dimension 2 over Rational Field and
1206
+ Set of elements of Integer Ring
1205
1207
"""
1208
+
1209
+ @staticmethod
1210
+ def __classcall__ (cls , X , Y , * args , ** kwds ):
1211
+ r"""
1212
+ Convert the operands to instances of :class:`Set_object` if necessary.
1213
+
1214
+ TESTS::
1215
+
1216
+ sage: from sage.sets.set import Set_object_binary
1217
+ sage: X = QQ^2
1218
+ sage: Y = ZZ
1219
+ sage: Set_object_binary(X, Y, "union", "\\cup")
1220
+ Set-theoretic union of
1221
+ Set of elements of Vector space of dimension 2 over Rational Field and
1222
+ Set of elements of Integer Ring
1223
+ """
1224
+ if not isinstance (X , Set_object ):
1225
+ X = Set (X )
1226
+ if not isinstance (Y , Set_object ):
1227
+ Y = Set (Y )
1228
+ return type .__call__ (cls , X , Y , * args , ** kwds )
1229
+
1206
1230
def __init__ (self , X , Y , op , latex_op ):
1207
1231
r"""
1208
1232
Initialization.
0 commit comments