Re: [sage-devel] Question about factories, representations and multiple classes

2022-06-09 Thread 'Travis Scrimshaw' via sage-devel
> > The __classcall_private__() mechanism works well for this kind of > dispatching > > with lots of examples within Sage for this. > > Agreed, and this is fairly standard. However, I am still skeptical about > the > fact this mechanism prevents deep copies... This limits the user's > abili

Re: [sage-devel] Question about factories, representations and multiple classes

2022-06-08 Thread Antoine Leudière
On Tue, 2022-06-07 at 23:03 -0700, 'Travis Scrimshaw' via sage-devel wrote: > > I'm also relatively new to Sage development, but one thing I can think of is > > that you could create a constructor module for your implementation of > > Drinfeld module. In short, the way I see it is that you would h

Re: [sage-devel] Question about factories, representations and multiple classes

2022-06-08 Thread Antoine Leudière
Thanks John for the answer. On Tue, 2022-06-07 at 08:41 -0700, John H Palmieri wrote: > Isn't this because you're using CachedRepresentation? From the documentation: > > Instances of a class have a *cached representation behavior* when several > instances constructed with the same arguments share

Re: [sage-devel] Question about factories, representations and multiple classes

2022-06-07 Thread 'Travis Scrimshaw' via sage-devel
> > I'm also relatively new to Sage development, but one thing I can think of > is that you could create a constructor module for your implementation of > Drinfeld module. In short, the way I see it is that you would have a new > module named "constructor" with a class "constructor.FiniteDrinfe

Re: [sage-devel] Question about factories, representations and multiple classes

2022-06-07 Thread davida...@gmail.com
Hello Antoine, I'm also relatively new to Sage development, but one thing I can think of is that you could create a constructor module for your implementation of Drinfeld module. In short, the way I see it is that you would have a new module named "constructor" with a class "constructor.FiniteD

Re: [sage-devel] Question about factories, representations and multiple classes

2022-06-07 Thread John H Palmieri
Isn't this because you're using CachedRepresentation? From the documentation : Instances of a class have a *cached representation behavior* when several instances constructed with the same arguments s

Re: [sage-devel] Question about factories, representations and multiple classes

2022-06-07 Thread Antoine Leudière
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(CachedRepre

Re: [sage-devel] Question about factories, representations and multiple classes

2022-05-14 Thread Nils Bruin
It's probably worth pointing out that __classcall_private__ is not a standard python facility. It looks like you need class Foo(metaclass=ClasscallMetaclass): to make it work on Foo. On Saturday, 14 May 2022 at 20:21:48 UTC-7 Travis Scrimshaw wrote: > For this you want to use __classcall_priva

Re: [sage-devel] Question about factories, representations and multiple classes

2022-05-14 Thread 'Travis Scrimshaw' via sage-devel
For this you want to use __classcall_private__ as otherwise you would likely end up in an infinite loop when you try to construct the subclass. There are lots of examples of this in the Sage library code. Best, Travis On Sunday, May 15, 2022 at 5:42:49 AM UTC+9 Eric Gourgoulhon wrote: > Hi,

Re: [sage-devel] Question about factories, representations and multiple classes

2022-05-14 Thread Eric Gourgoulhon
Hi, Le samedi 14 mai 2022 à 00:07:02 UTC+2, David Roe a écrit : > I think the following should work: > > class MyObject: > def __classcall__(cls, arg): > if isinstance(arg, special): > return typecall(MyObject_specific_case, arg) > else: > return t

Re: [sage-devel] Question about factories, representations and multiple classes

2022-05-13 Thread David Roe
I think the following should work: class MyObject: def __classcall__(cls, arg): if isinstance(arg, special): return typecall(MyObject_specific_case, arg) else: return typecall(MyObject, arg) plus the same __init__ you had before. I haven't checked