Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Adds InheritComparisonUniqueRepresentation class which is needed reso…
Browse files Browse the repository at this point in the history
…lve use of UniqueRepresentation with Element subclasses
  • Loading branch information
embray committed May 17, 2018
1 parent 6fc1e20 commit f896080
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/sage/structure/unique_representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,13 @@ class that inherits from :class:`UniqueRepresentation`: By adding
#******************************************************************************
from __future__ import print_function

from sage.misc import six
from six import with_metaclass
from sage.misc.cachefunc import weak_cached_function
from sage.misc.classcall_metaclass import ClasscallMetaclass, typecall
from sage.misc.fast_methods import WithEqualityById
from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass

class CachedRepresentation(six.with_metaclass(ClasscallMetaclass)):
class CachedRepresentation(with_metaclass(ClasscallMetaclass)):
"""
Classes derived from CachedRepresentation inherit a weak cache for their
instances.
Expand Down Expand Up @@ -1336,3 +1337,27 @@ class UniqueRepresentation(CachedRepresentation, WithEqualityById):
....:
sage: b = bla()
"""


class InheritComparisonUniqueRepresentation(with_metaclass(InheritComparisonClasscallMetaclass, UniqueRepresentation)):
"""
Implementation of :class:`UniqueRepresentation` that can be used as a
base class for classes that have :class:`InheritComparisonMetaclass` as
a metaclass (such as :class:`Element`).
EXAMPLES::
sage: from sage.structure.unique_representation \
....: import InheritComparisonUniqueRepresentation
sage: from sage.structure.element import Element
sage: class MyUniqueElement(InheritComparisonUniqueRepresentation,
....: Element):
....: def __init__(self, a):
....: self.a = a
....:
sage: el = MyUniqueElement(1)
sage: el is MyUniqueElement(1)
True
sage: el is MyUniqueElement(2)
False
"""

0 comments on commit f896080

Please sign in to comment.