From 4e73d8c04d15f9cbae067249c7ff39dec9d66eb1 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 27 Apr 2022 07:10:21 +0100 Subject: Avoided parallel assignment in template classes. --- django/template/base.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'django/template/base.py') diff --git a/django/template/base.py b/django/template/base.py index e83db6185c..4762d20516 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -307,7 +307,8 @@ class Token: The line number the token appears on in the template source. This is used for traceback information and gettext files. """ - self.token_type, self.contents = token_type, contents + self.token_type = token_type + self.contents = contents self.lineno = lineno self.position = position @@ -671,13 +672,12 @@ class FilterExpression: "%s|%s|%s" % (token[:upto], token[upto:start], token[start:]) ) if var_obj is None: - var, constant = match["var"], match["constant"] - if constant: + if constant := match["constant"]: try: var_obj = Variable(constant).resolve({}) except VariableDoesNotExist: var_obj = None - elif var is None: + elif (var := match["var"]) is None: raise TemplateSyntaxError( "Could not find variable at start of %s." % token ) @@ -686,10 +686,9 @@ class FilterExpression: else: filter_name = match["filter_name"] args = [] - constant_arg, var_arg = match["constant_arg"], match["var_arg"] - if constant_arg: + if constant_arg := match["constant_arg"]: args.append((False, Variable(constant_arg).resolve({}))) - elif var_arg: + elif var_arg := match["var_arg"]: args.append((True, Variable(var_arg))) filter_func = parser.find_filter(filter_name) self.args_check(filter_name, filter_func, args) -- cgit v1.3