Misrepresentation of tuple in dtml method

Recently I experienced an unexpected result while trying to render a tuple of two items in a diml-method.
I brought the code down to its essence.
In a dtml method I have the following code:

<dtml-var "tupleTest()">
<dtml-in "tupleTest()" prefix="v">
    <p><dtml-var "v_item"> </p>
</dtml-in>

The sequence of tuples is prepared in a function:
def tupleTest(self):
"test with a list of tuples"
tuplelist=[('a',1),('a',2),('b',1),('b',2)]
return tuplelist

The result when viewing the diml method looks like:
[('a', 1), ('a', 2), ('b', 1), ('b', 2)]

1

2

1

2

The call to <dtml-var "tupleTest()"> correctly displays the list of tuples, but the dtml-in sequence only displays the second item of each tuple.
This happens only when the tuple consists of 2 items. When the number of items is higher, the tuples are correctly displayed, also in the dtml-in sequence.

(Response originally via reply to this email).
> ... dtml-in treats lists of pairs specially ...

This is documented behavior.

I no longer know where the original documentation can be found
but I found in section "4.3.5.3.1" ("Iteration step variables")
of "http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html#c37ac15c14b4":

> sequence-item, sequence-key
> 
>     Usually, sequence-item is the current object and sequence-key
>     raises a TypeError exception. If, however, the current object
>     happens to be a pair, i.e. a tuple with two elements, then
>     sequence-key is the first and sequence-item the second element in
>     the pair[34].

The [34] refers to a footnote with the content "I think, this is
a misfeature".

I did not find it either on https://zope.readthedocs.io. What I found there is: 25. Appendix A: DTML Reference — Zope 5.9 documentation which tells the same story.

Related: given the age and crappiness of DTML, better use ZPT for generating markupish content or Jinja templates instead. DTML has many design flaws.

:grin: In the past I kept that chapter under my pillow and I still have a copy in my archive, so I should have known and it is not unlikely that I once knew...

Chapter 3....one of the most important artifacts of Zope :grin: