So I am trying to create a class with an initialization method that needs to get the type of the object being created in order to properly set the default values of the init arguments.
To give a concrete example with code, say I have the following class:
def __init__(self, foo, bar=type(self).some_class_variable, ham=type(self).some_other_class_variable):
self.foo = foo
self.bar = bar
self.ham = self.some_function(ham)
This is the functionality I am looking for, but my IDE is saying "self" is not defined
which I can understand, as self
has yet to be instantiated. So my question is how would I go about implementing this properly? I do not want to "hardcode" the class type in where I currently have type(self)
because subclasses of this class may have their own values for some_class_variable
and some_other_class_variable
and I want those subclasses to use the class variable corresponding to their type.
My solution needs to work in Python 3.6 & Python 3.7 but I would really prefer to find a solution that works in all versions of Python 3.6 and later if possible.