title: Could we implement generator using class?
body: <p>when we look at the Python documentation we could see that generators are always defined using yield statement, but in the Internet we could see that some people are trying to implement generators using classes (eg. here <a href="https://stackoverflow.com/questions/42983569/how-to-write-a-generator-class">How to write a generator class?</a>). </p>
  
  <p>Here is example generator implementation using classes:</p>
  
  <pre><code>from collections import Generator
  class Fib(Generator):
      def __init__(self):
          self.a, self.b = 0, 1        
      def send(self, ignored_arg):
          return_value = self.a
          self.a, self.b = self.b, self.a+self.b
          return return_value
      def throw(self, type=None, value=None, traceback=None):
          raise StopIteration
  </code></pre>
  
  <p>When we execute it in repl we can see it is not the generator, but ordinary object. It only tries to behave like generator.</p>
  
  <pre><code>&gt;&gt;&gt; x = Fib()
  &gt;&gt;&gt; x
  &lt;__main__.Fib object at 0x7f05a61eab70&gt;
  </code></pre>
  
  <p>When we look at PEP 342:</p>
  
  <blockquote>
    <ol start="4">
    <li>Add a close() method for generator-iterators, which raises GeneratorExit at the point where the generator was paused.</li>
    </ol>
  </blockquote>
  
  <p>I think it is not possible to meet that condition using own implementation with classes.</p>
  
  <p>Am I wrong? Is it really possible to implement real generator using classes?</p>