Using "tal:define" to define a name that is also a Python builtin cannot pass values to macros
Bug #701627 reported by
Gary Poster
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Chamelon Core |
New
|
Undecided
|
Unassigned | ||
Launchpad itself |
Triaged
|
Low
|
Unassigned | ||
z3c.pt |
New
|
Undecided
|
Unassigned |
Bug Description
Using "tal:define" to define a name that is also a Python builtin will not work well to pass values to macros--the builtin will win in the macro (Examples are "file" in Launchpad's productrelease-
A reasonable work-around is to not use names that are also Python builtins for this purpose.
Because of the easy work-around and the relatively rare occurrence of the problem, I don't think this needs to be fixed for the Launchpad Chameleon integration (https:/
To post a comment you must log in.
Although this error is relatively easy to work-around (stop using python builtins or reserved names as variable names in tal:define), it's hard to understand what happens by the error message.
Here is a simple reproduction. Replace the code in src/chameleon/ tests/templates /helloworld. pt with:
<div xmlns="http:// www.w3. org/1999/ xhtml" tal:define="class 'class'">
Hello World!
</div>
And the following error is raised:
Traceback (most recent call last): leo/Workspace/ shome-212- 20110125/ rebootstrap. 1.parts/ python2. 6/lib/python2. 6/doctest. py", line 1253, in __run
compileflags, 1) in test.globs leo/Workspace/ 2.12-perf/ src/Chameleon/ src/chameleon/ core/template. py", line 104, in __call__ **kwargs) leo/Workspace/ 2.12-perf/ src/Chameleon/ src/chameleon/ core/template. py", line 402, in render leo/Workspace/ 2.12-perf/ src/Chameleon/ src/chameleon/ zpt/template. py", line 17, in render leo/Workspace/ 2.12-perf/ src/Chameleon/ src/chameleon/ core/template. py", line 229, in render and_render( kwargs, utils.emptydict, None, True) leo/Workspace/ 2.12-perf/ src/Chameleon/ src/chameleon/ core/template. py", line 382, in cook_and_render leo/Workspace/ 2.12-perf/ src/Chameleon/ src/chameleon/ core/template. py", line 189, in cook_and_render macro, global_scope) leo/Workspace/ 2.12-perf/ src/Chameleon/ src/chameleon/ core/translatio n.py", line 1065, in __call__ Suite(source) leo/Workspace/ 2.12-perf/ src/Chameleon/ src/chameleon/ core/codegen. py", line 213, in __init__ leo/Workspace/ 2.12-perf/ src/Chameleon/ src/chameleon/ ast/astutil. py", line 22, in parse
File "/home/
File "<doctest template.txt[7]>", line 1, in <module>
print t()
File "/home/
return self.render(
File "/home/
return super(TemplateFile, self).render(*args, **kwargs)
File "/home/
return super(PageTemplate, self).render(*args, **kwargs)
File "/home/
return self.cook_
File "/home/
args, slots, macro, global_scope)
File "/home/
source = self.compiler(
File "/home/
suite = codegen.
File "/home/
node = parse(source, self.mode)
File "/home/
return compile(source, '', mode, _ast.PyCF_ONLY_AST)
File "<string>", line 22
class = 'class'
^
SyntaxError: invalid syntax