empty generator function causes traceback

Reported by Luc Saffre on 2011-11-29
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Appy
Undecided
Unassigned

Bug Description

If I repeat a paragraph using the following formula::

  do text for pp in properties_list()

and if `properties_list()` is a generator function,
then appy.pod works only correctly if the generator function actually yields values.

See attached demo of the bug.
The docstring in test.py explains a simple workaround.
Not urgent, but worth a closer look.

Luc Saffre (luc-saffre) wrote :
Luc Saffre (luc-saffre) wrote :

(I just stumbled again over this bug)

To solve this, I suggest to change one line in appy.pod.actions.Action.do() method (near the end):

        if hasHiddenVariable:
            context[self.iter] = hiddenVariable
        else:
            #~ if self.exprResult:
            if context.has_key(self.iter):
                del context[self.iter]

See also http://code.activestate.com/recipes/413614-testing-for-an-empty-iterator/
for another facet of this problem: you cannot simply test "if x" to see if an iterator is empty.
This works for lists and tuples, but not for generator functions.

Luc

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Bug attachments