I thank all of you for your answers. And sorry for taking a bit long to reply!
After many trys and errors, here is something that works for me:
```
from sage.structure.sage_object import SageObject
from sage.structure.unique_representation import CachedRepresentation
class MyInteger(CachedRepresentation, SageObject):
@staticmethod
def __classcall_private__(cls, n):
if n % 2 == 0:
return MyInteger_even(n)
else:
return cls.__classcall__(cls, n)
def __init__(self, n):
self.n = n
class MyInteger_even(MyInteger):
def __init__(self, n):
self.n = n
self.half = n // 2
```
However, this has a major drawback, as all instances that have same data are
references to one another. And I don't find any way to bypass that:
```
sage: from copy import deepcopy
sage: s1 = MyInteger(2)
sage: s2 = MyInteger(2)
sage: s3 = deepcopy(s2)
sage: s1 == s2
True
sage: s1 is s2
True
sage: s1 == s3
True
sage: s1 is s3
True
sage: s1.n
2
sage: s3.n = 5
sage: s1.n
5
sage:
```
I appreciate that this may not be a problem for classes representing sets and
categories (like `EuclideanSpace`). But for classes representing children
elements, this may cause problems. And this is the case for me, as I need this
for `FiniteDrinfeldModule` and `FiniteDrinfeldModule_rank_two`
(
https://trac.sagemath.org/ticket/33713).
Is there a way to avoid this?
Kindest regards,
Antoine
> --
> You received this message because you are subscribed to a topic in the Google
> Groups "sage-devel" group.
> To unsubscribe from this topic, visit
>
https://groups.google.com/d/topic/sage-devel/PaUReuoxEXI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
>
https://groups.google.com/d/msgid/sage-devel/a8bc696f-7887-41b2-8fe9-af3ac055eb71n%40googlegroups.com
> .