Ticket #7557: type_check.diff

File type_check.diff, 1.1 KB (added by Yohann Gabory, 11 years ago)

use six.string_type instead of basestring for python3 compatibility. Added a test to check that a non string value raise a TypeError

  • django/template/base.py

    diff --git a/django/template/base.py b/django/template/base.py
    index c5bddaf..fb6b309 100644
    a b class Variable(object):  
    690690        self.lookups = None
    691691        self.translate = False
    692692        self.message_context = None
    693 
     693        if not isinstance(var, six.string_types):
     694            raise TypeError(
     695                "Variable must be a string or number, got %s" % type(var))
    694696        try:
    695697            # First try to treat this variable as a number.
    696698            #
  • tests/template_tests/test_parser.py

    diff --git a/tests/template_tests/test_parser.py b/tests/template_tests/test_parser.py
    index 9422da8..d5d8ec4 100644
    a b class ParserTests(TestCase):  
    8585        self.assertRaises(TemplateSyntaxError,
    8686            Variable, "article._hidden"
    8787        )
     88        # Variables should raise on non string type
     89        self.assertRaises(TypeError, Variable({}))
    8890
    8991    @override_settings(DEBUG=True, TEMPLATE_DEBUG=True)
    9092    def test_compile_filter_error(self):
Back to Top