I have two classes that look like this:
class BaseClass(object):
def the_dct(self):
return self.THE_DCT
class Kid(BaseClass):
THE_DCT = {'vars': 'values'}
# Code i ll be running
inst = Kid()
print(inst.the_dct)
Inheritance has to be this way; second class containing THE_DCT and first class containing def the_dct.
It works just fine, but my problem is that i get a warning in Pycharm (unresolved attribute reference), about THE_DCT in BaseClass.
- Is there a reason why it's warning me (as in why i should avoid it)?
- Is there something i should do differently?
BaseClassthere is noTHE_DCT. "Is there something i should do differently?" - you could include an empty dictionaryTHE_DCT = {}inBaseClass, or just ignore the warning. - jonrsharpeBaseClass().the_dct()will fail. - jonrsharpeBaseClassshouldn't be instantiated directly, this won't be a problem. You could also look into abstract base classes. - jonrsharpe