0

I have a Parent and Child class as follows:

class Parent:
  def __init__(self):
    self.__set_config():

  def __set_config(self):
    raise NotImplementedError

  def run(self):
    # do something

class Child:
  def __set_config(self):
    self.config = {"foo": "bar"}

The expectation is that, in the parent class's call to __set_config(), the child class's overridden method would be called. What in fact happens is that NotImplementedError is raised instead of the config object being set.

Is it not possible to

  • enforce implementation in a child class of a method,
  • and also call the same method in the parent class?
kyuden
  • 197
  • 1
  • 11
  • Those two underscores at the front of the variable made it a [Private variable](https://docs.python.org/3/tutorial/classes.html?highlight=private#private-variables). If you changed the name to `_set_config`, it would work. – tdelaney Apr 05 '23 at 03:38
  • Also, `Child` does not inherit from `Parent`, so it wouldn't find the method anyway. – jasonharper Apr 05 '23 at 03:55

0 Answers0