Using "tal:define" to define a name that is also a Python builtin cannot pass values to macros

Bug #701627 reported by Gary Poster
8
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-portlet-data.pt and "type" in zope.app.apidoc).

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://dev.launchpad.net/LEP/Chameleon) to be a success.

Tags: chameleon
Revision history for this message
LeoRochael (leorochael) wrote :

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):
      File "/home/leo/Workspace/shome-212-20110125/rebootstrap.1.parts/python2.6/lib/python2.6/doctest.py", line 1253, in __run
        compileflags, 1) in test.globs
      File "<doctest template.txt[7]>", line 1, in <module>
        print t()
      File "/home/leo/Workspace/2.12-perf/src/Chameleon/src/chameleon/core/template.py", line 104, in __call__
        return self.render(**kwargs)
      File "/home/leo/Workspace/2.12-perf/src/Chameleon/src/chameleon/core/template.py", line 402, in render
        return super(TemplateFile, self).render(*args, **kwargs)
      File "/home/leo/Workspace/2.12-perf/src/Chameleon/src/chameleon/zpt/template.py", line 17, in render
        return super(PageTemplate, self).render(*args, **kwargs)
      File "/home/leo/Workspace/2.12-perf/src/Chameleon/src/chameleon/core/template.py", line 229, in render
        return self.cook_and_render(kwargs, utils.emptydict, None, True)
      File "/home/leo/Workspace/2.12-perf/src/Chameleon/src/chameleon/core/template.py", line 382, in cook_and_render
        args, slots, macro, global_scope)
      File "/home/leo/Workspace/2.12-perf/src/Chameleon/src/chameleon/core/template.py", line 189, in cook_and_render
        source = self.compiler(macro, global_scope)
      File "/home/leo/Workspace/2.12-perf/src/Chameleon/src/chameleon/core/translation.py", line 1065, in __call__
        suite = codegen.Suite(source)
      File "/home/leo/Workspace/2.12-perf/src/Chameleon/src/chameleon/core/codegen.py", line 213, in __init__
        node = parse(source, self.mode)
      File "/home/leo/Workspace/2.12-perf/src/Chameleon/src/chameleon/ast/astutil.py", line 22, in parse
        return compile(source, '', mode, _ast.PyCF_ONLY_AST)
      File "<string>", line 22
         class = 'class'
               ^
     SyntaxError: invalid syntax

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.