From: Ben Darnell Date: Sun, 14 Feb 2016 00:40:49 +0000 (-0500) Subject: Add defaults to template.ParseError arguments. X-Git-Tag: v4.4.0b1~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2dac2cfcf06aba8d52cb6ec11f1a3b46b2f7c27;p=thirdparty%2Ftornado.git Add defaults to template.ParseError arguments. Fixes #1631 --- diff --git a/tornado/template.py b/tornado/template.py index fa588991e..c7f26eff7 100644 --- a/tornado/template.py +++ b/tornado/template.py @@ -665,7 +665,7 @@ class ParseError(Exception): .. versionchanged:: 4.3 Added ``filename`` and ``lineno`` attributes. """ - def __init__(self, message, filename, lineno): + def __init__(self, message, filename=None, lineno=0): self.message = message # The names "filename" and "lineno" are chosen for consistency # with python SyntaxError. diff --git a/tornado/test/template_test.py b/tornado/test/template_test.py index d49d23279..7b21ce754 100644 --- a/tornado/test/template_test.py +++ b/tornado/test/template_test.py @@ -280,6 +280,11 @@ class ParseErrorDetailTest(unittest.TestCase): self.assertEqual("foo.html", cm.exception.filename) self.assertEqual(3, cm.exception.lineno) + def test_custom_parse_error(self): + # Make sure that ParseErrors remain compatible with their + # pre-4.3 signature. + self.assertEqual("asdf at None:0", str(ParseError("asdf"))) + class AutoEscapeTest(unittest.TestCase): def setUp(self):