wbond / pybars3

Handlebars.js template support for Python 3 and 2
GNU Lesser General Public License v3.0
179 stars 46 forks source link

Fixed a SyntaxError issue in _compiler.py with Python < 2.7.8 #59

Closed dwatteau closed 2 years ago

dwatteau commented 5 years ago

Hi,

pybars3-0.9.6 currently fails on CentOS 7.6 (its default Python version is 2.7.5) with the following kind of error:

  File "pybars/__init__.py", line 30, in <module>                               
    from pybars._compiler import (                                                                                        
  File "pybars/_compiler.py", line 902                                          
    exec(code + '\nresult = render(context, helpers=helpers, partials=partials, root=root)', ns)                          
SyntaxError: unqualified exec is not allowed in function '_render' it is a nested function   

It looks like this was an internal bug in early releases of Python 2.7 (https://bugs.python.org/issue21591) which was fixed around Python 2.7.8. Unfortunately, CentOS 7 still ships Python 2.7.5 by default.

Other projects worked around this by using an alternative syntax that doesn't trigger this error with early Python 2.7 versions: https://github.com/plone/plone.protect/pull/76/files#diff-41a4c6407f64bbc479d3af2fbfae7617, https://github.com/victorlei/smop/issues/129#issuecomment-444799736.

The following PR tries to replicate this workaround, to preserve Python 2.7 compatibility.

dwatteau commented 2 years ago

Closing this because I don't work on the project which required this workaround anymore, and Python 2.7 has been unsupported for a couple of years now.