Issue #18 open needs a little bit of work to be more helpful

created an issue

I noticed a few small issues as I was working through the generator koans today. First: {{{


def sum_it(self, seq): value = 0 for num in seq: # The local state of 'value' will be retained between iterations value += num yield value

def test_generator_keeps_track_of_local_variables(self):
    result = self.sum_it(range(2,5))
    self.assertEqual([9], list(result))

}}} The yield value statement should be indented to make it part of the loop. Otherwise it runs all in one go, yield only one final value, and doesn't illustrate retaining the value of 'value'. It looks just like a regular function instead of a generator and isn't as educational as it could be.

second: The koan {{{


def test_coroutines_can_take_arguments(self): result = self.simple_generator_method() self.assertEqual('peanut', next(result)) self.assertEqual('butter', next(result)) result.close() }}} should probably be moved later as coroutines aren't otherwise mentioned or covered until a few koans later. The given function also doesn't actually pass in any arguments or illustrate any coroutine functionality. It seems to work identically to earlier generator and iterator examples.

last, and least: There's a function named cube_me used in test_generator_method_with_parameter which returns the square of the input instead of the cube. So it should either be renamed or tweaked.

Comments (2)

  1. Greg Malcolm repo owner
    • changed status to open

    Thanks for the feedback! It might be a while before I get around to sorting this out, but I'm always happy to take pull request's if you get impatient waiting for me... :)

  2. Log in to comment