empty generator function causes traceback

Bug #897755 reported by Luc Saffre
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Appy
New
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.

Revision history for this message
Luc Saffre (luc-saffre) wrote :
Revision history for this message
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  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.