wbond / pybars3

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

Regression: Built-in functions take precedence over dict items #16

Closed viernullvier closed 8 years ago

viernullvier commented 9 years ago

I've noticed something strange while upgrading a larger project from pybars to pybars3:

pybars 0.0.4:

>>> import pybars
>>> comp = pybars.Compiler()
>>> fn = comp.compile(u"{{test.items}}")
>>> fn({"test": {"items": [1,2,3]}})
[u'[1, 2, 3]']

pybars3 0.9.1:

>>> import pybars
>>> comp = pybars.Compiler()
>>> fn = comp.compile(u"{{test.items}}")
>>> fn({"test": {"items": [1,2,3]}})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_templates/_template_1.py", line 26, in render
TypeError: items() takes no arguments (1 given)

It's possible to access the dict entry through lookup, but IMO it shouldn't be the only way just because of a naming conflict with a built-in class function. Maybe pybars3 should check for dict-ness before invoking hasattr()? (relevant lines)