The __init__ method of a class is used to initialize new objects, not create them. As such, it should not return any value. By including a yield expression in the method turns it into a generator method. On calling it will return a generator resulting in a runtime error.

The presence of a yield expression in an __init__ method suggests a logical error, so it is not possible to suggest a general fix.

In this example the __init__ method contains a yield expression. This is not logical in the context of an initializer.

  • Python: The __init__ method.