Edgewall Software

Opened 12 years ago

Closed 11 years ago

#45 closed defect (fixed)

<py:for> directive doesn't handle a structured list of variable

Reported by: cboos Owned by: cmlenz
Priority: minor Milestone: 0.3
Component: Template processing Version: devel
Keywords: py:for Cc:


I've got a backtrace while trying to enumerate the items of a dict:

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:py="http://markup.edgewall.org/" >

    <!--! This doesn't work -->
    <py:for each="idx, (k, v) in enumerate(dict(a=1, b=2).items())">
      <p>$idx: key=$k value=$v</p>

    <!--! This is a workaround -->
    <py:for each="idx, kv in enumerate(dict(a=1, b=2).items())">
      <p>$idx: key=${kv[0]} value=${kv[1]}</p>


This is either a bug, or a documentation issue, i.e. I think it's not absolutely necessary to support this, as the workaround is easy.

Would be nice to have it, though, or at least to have a better error message.

Attachments (0)

Change History (3)

comment:1 Changed 12 years ago by cboos

  • Version changed from 0.2 to devel

The backtrace in question:

Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "C:\Workspace\src\trac\Markup\trunk\markup\core.py", line 141, in render
    output = u''.join(list(generator))
  File "c:\workspace\src\trac\markup\trunk\markup\output.py", line 112, in __call__
    kind, data, pos = stream.next()
  File "c:\workspace\src\trac\markup\trunk\markup\output.py", line 529, in next
    return self.iterable.next()
  File "c:\workspace\src\trac\markup\trunk\markup\output.py", line 474, in __call__
    for kind, data, pos in chain(stream, [(None, None, None)]):
  File "C:\Workspace\src\trac\Markup\trunk\markup\core.py", line 202, in _ensure
    for event in stream:
  File "C:\Workspace\src\trac\Markup\trunk\markup\filters.py", line 147, in __call__
    for kind, data, pos in stream:
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 1022, in _match
    kind, data, pos = stream.next()
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 998, in _match
    for kind, data, pos in stream:
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 928, in _eval
    for kind, data, pos in stream:
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 986, in _flatten
    for event in self._flatten(substream, ctxt):
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 980, in _flatten
    for kind, data, pos in stream:
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 413, in __call__
    scope[name] = item[idx]
IndexError: tuple index out of range

(using r260)

comment:2 Changed 12 years ago by cmlenz

  • Milestone set to 0.3

Yeah, would be nice if that worked as expected.

comment:3 Changed 11 years ago by cmlenz

  • Resolution set to fixed
  • Status changed from new to closed

Should be fixed in [276].

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain cmlenz.
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.