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 typecall(MyObject, arg)
>
> plus the same __init__ you had before.  I haven't checked it though....
> David
>               
>

An alternative is to use __classcall_private__
For an example, see the class EuclideanSpace in
src/sage/manifolds/differentiable/examples/euclidean.py 
<https://github.com/sagemath/sage/blob/develop/src/sage/manifolds/differentiable/examples/euclidean.py>

EuclideanSpace(n) actually returns an instance of the subclass 
EuclideanPlane if n = 2 or of the subclass Euclidean3dimSpace if n = 3.

Best wishes,

Eric.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/39214e36-80fa-4a33-988a-852b1a225773n%40googlegroups.com.

Reply via email to