#441 closed defect (wontfix)
defined() returns False for names in parent context
Reported by: | jaraco@… | Owned by: | hodgestar |
---|---|---|---|
Priority: | minor | Milestone: | 0.6.1 |
Component: | General | Version: | 0.6 |
Keywords: | Cc: |
Description
I created this script to demonstrate the behavior.
import genshi.template template = ''' <root xmlns:py="http://genshi.edgewall.org/"> <p>${defined('foo')} / ${defined(foo)} / $foo</p> <p>${defined('bar')} / ${defined(bar)} / $bar</p> <p py:if="defined('foo')">foo defined as $foo</p> </root> ''' tmpl = genshi.template.MarkupTemplate(template) context = genshi.template.Context(foo='abc') context.push(genshi.template.Context(bar='xyz')) print(tmpl.generate(context).render('xhtml'))
It outputs the following:
<root> <p>False / False / abc</p> <p>True / False / xyz</p> </root>
So even though $foo is defined in the context, defined('foo') returns False.
Change History (3)
comment:1 Changed 13 years ago by hodgestar
- Owner changed from cmlenz to hodgestar
- Status changed from new to assigned
comment:2 Changed 13 years ago by hodgestar
- Resolution set to wontfix
- Status changed from assigned to closed
comment:3 Changed 13 years ago by anonymous
- Priority changed from critical to minor
Sure enough - it looks like my usage was wrong. If I push a dict instead of a Context, it works as expected.
This begs the question, should Context.push accept another context at all? If the only prescribed use-case is to push a dictionary, perhaps Context.push should reject pushing another context.
In any case, the disposition of this ticket is fine. Thanks for the help!
Note: See
TracTickets for help on using
tickets.
This happens because both the inner and outer Context objects define an item named 'defined'. The one from Context(bar='xyz') then overrides the one from Context(foo='xyz'). I think one should be calling Context.push() with a data dictionary, not a Context object. Arguably Genshi users shouldn't be pushing to Context objects at all (although there may be use cases I'm not imaging).
I'm closing this for now but feel free to re-open with more details about the issue.