I'm using Python 2.7 on Ubuntu 13.04. I'm building out a series of scheduled tasks to upload some data to a 3rd party API. I'm trying to build the tasks in a generic way so we can easily add more later. In doing so I've used some inheritance techniques that aren't working the way I expect. I think the MRO is pretty straight forward, but I must be doing something wrong because I get global name 'UpdateBase' is not defined
when trying to initialize the tasks.
Below is the inheritance structure I'm using.
class UpdateBase(PeriodicTask):
def __init__(self, table_type=None, update_type=constants.UPDATE_REALTIME,
cache_time=constants.CACHE_TIME_UPDATE):
super(UpdateBase, self).__init__()
self.table_type = table_type
self.update_type = update_type
self.cache_time = cache_time
self.filename = '{}-{}.{}'.format(
table_type, datetime.datetime.now(), self.update_type)
self.old_files = '{}-*'.format(table_type)
self.file_path = os.path.join(
constants.UPDATE_FILE_PATH, self.filename)
class UpdateAffiliates(UpdateBase):
def __init__(self, **kwargs):
super(UpdateAffiliates, self).__init__(
table_type=constants.AFFILIATES, **kwargs)
class OverlapAffiliates(UpdateAffiliates):
def __init__(self, **kwargs):
super(OverlapAffiliates, self).__init__(
update_type=constants.UPDATE_OVERLAP,
cache_time=constants.UPDATE_OVERLAP, **kwargs)
Any suggestions as to why I'm getting this error?
EDIT1:
It seems something else must be causing this NameError
. I've built several hierarchies testing this MRO. I've tested every which way I can think of and everything is fine. If anyone can think of anything I can check, change or include to help I would appreciate it.
One example of test code:
#!/usr/bin/env python
CONST1 = 'const_1'
CONST2 = 'const_2'
CONST3 = 'const_3'
class Test1(object):
internal_val = 'internal 1'
def __init__(self, val1=None, val2=CONST2, val3=CONST3):
print 'val1: {}\nval2: {}\nval3: {}\ninternal_val: {}'.format(
val1, val2, val3, self.internal_val)
class Test2(Test1):
def __init__(self, **kwargs):
super(Test2, self).__init__(val1=CONST1, **kwargs)
class Test3(Test2):
internal_val = 'internal 3'
def __init__(self, **kwargs):
super(Test3, self).__init__(
val2='test3 val2', val3='test3 val3', **kwargs)
def main():
test1 = Test1()
test2 = Test2()
test3 = Test3()
if __name__ == '__main__':
main()