So it works now, correct?

Best,
Travis


On Friday, September 27, 2019 at 12:42:23 AM UTC+10, Salvatore Stella wrote:
>
> Oops, I think that I figured out where the mistake was. Here is the 
> correct 
> code: 
>
> class OldFoo(UniqueRepresentation): 
>
>     @staticmethod 
>     def __classcall__(self, data, **kwargs): 
>         hashable_data = tuple(data) 
>         kwargs['some_default_option'] = 'bar' 
>         return super(OldFoo, self).__classcall__(self, hashable_data, 
> **kwargs) 
>
>     def __init__(self, data, **kwargs): 
>         self._data = data 
>         self._some_default_option = kwargs['some_default_option'] 
>
>     def __repr__(self): 
>         return 'Data = %s, option = %s'%(self._data, 
> self._some_default_option) 
>
> class NewFoo(OldFoo): 
>
>     @staticmethod 
>     def __classcall__(self, data, **kwargs): 
>         new_data = data+data 
>         return super(NewFoo, self).__classcall__(self, new_data, **kwargs) 
>
>
> Thanks 
> S. 
>
>
>
> * Travis Scrimshaw <tsc...@ucdavis.edu <javascript:>> [2019-09-25 
> 16:59:13]: 
>
> >Although it almost sounds like you should be doing the NewFoo preparsing 
> >inside NewFoo.__classcall__ (or NewFoo.__classcall_private__), which then 
> >should get passed up and handled by OldFoo.__classcall__. You might need 
> >some extra *args or **kwds to the __init__ and/or __classcall__ to handle 
> >this. The other option would be to separate out the preparsing portion 
> into 
> >a separate @classmethod or @staticmethod. 
> > 
> >Best, 
> >Travis 
> > 
> > 
> >On Thursday, September 26, 2019 at 9:55:56 AM UTC+10, Travis Scrimshaw 
> >wrote: 
> >> 
> >> Make OldFoo.__classcall_private__, then it is not inherited. 
> >> 
> >> Best, 
> >> Travis 
> >> 
> >> 
> >> On Thursday, September 26, 2019 at 8:22:23 AM UTC+10, Salvatore Stella 
> >> wrote: 
> >>> 
> >>> Dear All, 
> >>> I would like to make a new class inheriting from a class based on 
> >>> UniqueRepresentation. My goal, among other things, is to preparse the 
> >>> arguments a little before calling the class I am inheriting from. 
> >>> Unfortunately this class also does some preparsing via __classcall__ 
> to 
> >>> make 
> >>> the input hashable. Could you point me to the correct way of setting 
> this 
> >>> up? 
> >>> 
> >>> Sketch of the situation: 
> >>> 
> >>> class OldFoo(UniqueRepresentation): 
> >>> 
> >>>     @staticmethod 
> >>>     def __classcall__(self, data): 
> >>>        # make data hashable 
> >>>        return super(oldFoo, self).__classcall__(self, hashable_data) 
> >>> 
> >>>     def __init__(self, hashable_data): 
> >>>         # do something 
> >>> 
> >>> class NewFoo(OldFoo): 
> >>> 
> >>>     # First neutralize OldFoo __classcall__ 
> >>>     __classcall__ = None 
> >>> 
> >>>     def __init__(self, data): 
> >>>         # preparse data then initialize OldFoo 
> >>> 
> >>> 
> >>> If __classcall__ were not there I would call OldFoo.__init__ but this 
> >>> does 
> >>> not seem to work with OldFoo.__classcall__ 
> >>> 
> >>> 
> >>> Thanks 
> >>> S. 
> >>> 
> >>> 
> >>> 
> >>> 
> > 
> >-- 
> >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-...@googlegroups.com <javascript:>. 
> >To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sage-devel/5475d883-8c54-4a8b-8fb5-f33859e464a3%40googlegroups.com.
>  
>
>
>

-- 
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/869947d6-8388-4455-96a2-75550bad4dd1%40googlegroups.com.

Reply via email to