Thank you Travis for your reply. Here is an attempt at implementing your
suggestion that does not work: it looks like OldFoo.__classcall__ is skipped
and OldFoo.__init__ is run directly instead. This is not what I want: I would
like the preparsing in OldFoo to still be performed after the preparsing in
NewFoo
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(OldFoo, self).__classcall__(self, new_data, **kwargs)
If you try this code it runs as follows:
sage: OldFoo([0,1,2,3])
Data = (0, 1, 2, 3), option = bar
sage: NewFoo([0,1,2,3])
...
TypeError: unhashable type: 'list'
sage: NewFoo((0,1,2,3))
...
KeyError: 'some_default_option'
Thanks
S.
* Travis Scrimshaw <
tsc...@ucdavis.edu> [2019-09-25 16:59:13]:
>--
>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+...@googlegroups.com.
>To view this discussion on the web visit
https://groups.google.com/d/msgid/sage-devel/5475d883-8c54-4a8b-8fb5-f33859e464a3%40googlegroups.com.