Set of all objects of a given Python class#

sage.sets.pythonclass.Set_PythonType(typ)#

Return the (unique) Parent that represents the set of Python objects of a specified type.

EXAMPLES:

sage: from sage.sets.pythonclass import Set_PythonType
sage: Set_PythonType(list)
Set of Python objects of class 'list'
sage: Set_PythonType(list) is Set_PythonType(list)
True
sage: S = Set_PythonType(tuple)
sage: S([1,2,3])
(1, 2, 3)

S is a parent which models the set of all lists:

sage: S.category()
Category of sets
class sage.sets.pythonclass.Set_PythonType_class#

Bases: Set_generic

The set of Python objects of a given class.

The elements of this set are not instances of Element; they are instances of the given class.

INPUT:

  • typ – a Python (new-style) class

EXAMPLES:

sage: from sage.sets.pythonclass import Set_PythonType
sage: S = Set_PythonType(int); S
Set of Python objects of class 'int'
sage: int('1') in S
True
sage: Integer('1') in S
False

sage: Set_PythonType(2)
Traceback (most recent call last):
...
TypeError: must be initialized with a class, not 2
cardinality()#

EXAMPLES:

sage: from sage.sets.pythonclass import Set_PythonType
sage: S = Set_PythonType(bool)
sage: S.cardinality()
2
sage: S = Set_PythonType(int)
sage: S.cardinality()
+Infinity
object()#

EXAMPLES:

sage: from sage.sets.pythonclass import Set_PythonType
sage: Set_PythonType(tuple).object()
<... 'tuple'>