Element Wrapper¶
Wrapping Sage or Python objects as Sage elements.
AUTHORS:
Nicolas Thiery (2008-2010): Initial version
Travis Scrimshaw (2013-05-04): Cythonized version
-
class
sage.structure.element_wrapper.
DummyParent
(name)¶ Bases:
sage.structure.unique_representation.UniqueRepresentation
,sage.structure.parent.Parent
A class for creating dummy parents for testing
ElementWrapper
-
class
sage.structure.element_wrapper.
ElementWrapper
¶ Bases:
sage.structure.element.Element
A class for wrapping Sage or Python objects as Sage elements.
EXAMPLES:
sage: from sage.structure.element_wrapper import DummyParent sage: parent = DummyParent("A parent") sage: o = ElementWrapper(parent, "bla"); o 'bla' sage: isinstance(o, sage.structure.element.Element) True sage: o.parent() A parent sage: o.value 'bla'
Note that
o
is not an instance ofstr
, but rather contains astr
. Therefore,o
does not inherit the string methods. On the other hand, it is provided with reasonable default implementations for equality testing, hashing, etc.The typical use case of
ElementWrapper
is for trivially constructing new element classes from pre-existing Sage or Python classes, with a containment relation. Here we construct the tropical monoid of integers endowed withmin
as multiplication. There, it is desirable not to inherit thefactor
method fromInteger
:sage: class MinMonoid(Parent): ....: def _repr_(self): ....: return "The min monoid" ....: sage: M = MinMonoid() sage: class MinMonoidElement(ElementWrapper): ....: wrapped_class = Integer ....: ....: def __mul__(self, other): ....: return MinMonoidElement(self.parent(), min(self.value, other.value)) sage: x = MinMonoidElement(M, 5); x 5 sage: x.parent() The min monoid sage: x.value 5 sage: y = MinMonoidElement(M, 3) sage: x * y 3
This example was voluntarily kept to a bare minimum. See the examples in the categories (e.g.
Semigroups().example()
) for several full featured applications.Warning
Versions before trac ticket #14519 had parent as the second argument and the value as the first.
-
value
¶
-
-
class
sage.structure.element_wrapper.
ElementWrapperCheckWrappedClass
¶ Bases:
sage.structure.element_wrapper.ElementWrapper
An
element wrapper
such that comparison operations are done against subclasses ofwrapped_class
.-
wrapped_class
¶ alias of
builtins.object
-
-
class
sage.structure.element_wrapper.
ElementWrapperTester
¶ Bases:
sage.structure.element_wrapper.ElementWrapper
Test class for the default
__copy()
method of subclasses ofElementWrapper
.-
append
(x)¶
-