Fix BytecodeCache error on Python 3 #240

Closed
wants to merge 2 commits into from

4 participants

@msabramo

This adds a test that reproduces an error with BytecodeCache on Python 3:

marca@marca-mac:~/dev/git-repos/jinja2$ .tox/py33/bin/python run-tests.py -v jinja2.testsuite.bytecode_cache.ByteCodeCacheTestCase
test_simple (jinja2.testsuite.bytecode_cache.ByteCodeCacheTestCase) ... ERROR

======================================================================
ERROR: test_simple (jinja2.testsuite.bytecode_cache.ByteCodeCacheTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/marca/dev/git-repos/jinja2/jinja2/testsuite/bytecode_cache.py", line 29, in test_simple
    tmpl = env.get_template('test.html')
  File "/Users/marca/dev/git-repos/jinja2/jinja2/environment.py", line 791, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/Users/marca/dev/git-repos/jinja2/jinja2/environment.py", line 765, in _load_template
    template = self.loader.load(self, name, globals)
  File "/Users/marca/dev/git-repos/jinja2/jinja2/loaders.py", line 119, in load
    bucket = bcc.get_bucket(environment, name, filename, source)
  File "/Users/marca/dev/git-repos/jinja2/jinja2/bccache.py", line 176, in get_bucket
    key = self.get_cache_key(name, filename)
  File "/Users/marca/dev/git-repos/jinja2/jinja2/bccache.py", line 163, in get_cache_key
    if isinstance(filename, unicode):
NameError: global name 'unicode' is not defined

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

and then fixes it by replacing unicode with jinja2._compat.text_type.

msabramo added some commits Jun 5, 2013
@msabramo msabramo Add test (jinja2.testsuite.bytecode_cache.ByteCodeCacheTestCase) for
BytecodeCache that fails on Python 3 because it uses `unicode`
a8ce6b8
@msabramo msabramo Fix Python 3 compatibility of BytecodeCache by checking for `if
isinstance(filename, text_type)` instead of `if isinstance(filename,
unicode)`
39fe045
@msabramo

Oops. I just noticed that this is almost identical to PR #228.

This also fixes issue #227, which I don't think should've been closed.

@extesy

@mitsuhiko Could you please merge this PR? This bug breaks Jinja2 on Python 3.

@domenkozar

+1, this breaks pyramid_jinja2

@mitsuhiko
The Pallets Projects member

Thanks, fixed in 2.7-maintenance and master.

@mitsuhiko mitsuhiko closed this Aug 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment