﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
591	Changing outer-defined variables within py:for scope are lost for string but work for dict	Ronan Jouchet <ronan@…>	cmlenz	"== Problem ==

When defining variables in outermost scope, changes from within py:for scope work as expected for dictionaries (changes persist when leaving py:for scope), but are lost for strings when leaving the py:for scope.

== Example ==

1. Define variable in an initial template <?python ?> block:

{{{
<?python
  users = ['Bob', 'Alice']
  currentUser = users[0]
  dict = {'currentUser': users[0]}
?>
}}}

2. Later in the template and in the context of a <py:for> block, update it:

{{{
<ul>
  <li py:for ""user in users"">
    <?python
    currentUser = user
    dict['currentUser'] = user
    # here, both the string and dict are properly updated
    ?>
  </li>
</ul>
}}}

3. Later in the template and out of the previous <py:for> scope where the update happened, use the variable:

{{{
<span>
  ${currentUser}<br />
  ${dict['currentUser']}
</span>
}}}

'''Expected''': both variables contain Alice

'''Actual''': the dict properly contains 'Alice', but the string contains 'Bob'

== Thoughts ==

A.1. [https://groups.google.com/forum/#!topic/genshi/TtcpVturEx0 This mailing-list post] is not exactly my case. Unlike in the mailing list, my case does declare variables ''before'' using them in a <py:for> scope, but changes within the <py:for> are scrapped nevertheless.

A.2. The [http://genshi.edgewall.org/wiki/GenshiVsKid GenshiVsKid page] also mentions ''""Proper scoping of variables. Names do not leak into outer scopes""'', but here the initial scope was the py:for outer one. Changes in inner scopes ''should'' be persisted in the initial scope.

B. Plus, the fact that Genshi's behavior differs between Python types (dict vs. string) reinforces the feeling that this is a bug.

== Environment ==

Problem is always reproducible, under both Genshi 0.6.1 and 0.7, in a fresh Python 2.7.6 virtualenv with the bare minimum required by the tutorial (pip install CherryPy FormEncode Genshi).

I derived the official 'Geddit' tutorial into an example, see attachment, which renders into:

[[Image(https://dl.dropboxusercontent.com/u/207077637/genshi_scope_bug_dictVsString.png)]]"	defect	new	major	0.9	Template processing	0.6		scoping, scope, typing, stack	
