Opened 16 years ago
#258 new defect
SystemError in Markup.join with non-sequence argument
Reported by: | djc@… | Owned by: | cmlenz |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | General | Version: | 0.5.1 |
Keywords: | Cc: |
Description
There is a bug in the Markup_join function in _speedups.c, which causes a SystemError? to be raised if a non-sequence is passed to it:
>>> Markup(u', ').join(x for x in ['asdf', 'xyz']) Traceback (most recent call last): File "<stdin>", line 1, in <module> SystemError: error return without exception set
Attached is a patch against trunk r953 which fixes the problem.
I noticed the problem when I was using a generator expression as the argument to Markup.join, which works correctly with the pure-Python version, but Markup_join in _speedups.c requires a sequence. The second patch (against trunk r953) adds support for iterables, by growing a list rather than allocating a tuple upfront. I suspect this will be slower in the case where the argument is a real sequence (though I've not tested by how much), so maybe it is better to leave this out?
Note that the generator expression usage is fixed by the first patch alone, because Genshi catches the TypeError? and falls back to the pure-Python version which supports all iterables.