Dynamically assigning element_class

32 views
Skip to first unread message

Jeroen Demeyer

unread,
Oct 6, 2015, 7:55:01 AM10/6/15
to sage-devel
Hi,

Suppose I have some Parent class MyParent which can handle multiple
element classes. The choice of element class depends on the arguments to
__init__(). What is the recommended way to deal with this? Is it safe to
do the following in Parent.__init__()?

self.element_class = MyChosenElement

Simon King

unread,
Oct 6, 2015, 8:49:39 AM10/6/15
to sage-...@googlegroups.com
Hi Jeroen,
I suppose it is better todo

self.Element = MyChosenElementClass

because self.element_class is constructed from self.Elemenet *plus*
additional stuff. So, if you directly override the lazy attribute
self.element_class with MyChosenElementClass, then you will lose all the
additional stuff.

Best regards,
Simon


Travis Scrimshaw

unread,
Oct 6, 2015, 8:57:04 AM10/6/15
to sage-devel
Hey Jeroen,
   I think I've done what Simon is recommending at some point as well. Just be sure to do it before doing Parent.__init__(...).

Best,
Travis
Reply all
Reply to author
Forward
0 new messages