In a program that I'm writing, I wanted to make a ConfigParser that's read only so that it can safely be used globally. I didn't realize this, but apparently the SafeConfigParser is an old-style class, thus I had to subclass it like this:
class ConstParser(SafeConfigParser, object):
"""This is a implementation of the SafeConfigParser that can't
write any values. This is to ensure that it can only be filled
once and won't get messy with multiple modules writing to it."""
def __init__(self, files, defaults={}):
super(ConstParser, self).__init__(defaults)
self.read(files)
def set(self, *args, **argd):
raise NotImplementedError()
def write(self, *args, **argd):
raise NotImplementedError()
def remove_option(self, *args, **argd):
raise NotImplementedError()
def remove_section(self, *args, **argd):
raise NotImplementedError()
If I didn't use object as a mixin, the call to SafeConfigParser's __init__
method didn't work. Now, I'm sure that there are better ways to do what I want to do, but now I'm curious: is this ok to do in general?
I mean, I can't think of any reason why this would be a bad thing, but it still gives me bad feelings. Are they justified, or am I just being paranoid?