Include result origin in broken conditional message instead of result (#85695) (#85697)

(cherry picked from commit b1fc98c8ad)

Co-authored-by: Matt Clay <matt@mystile.com>
pull/85698/head
Matt Davis 4 months ago committed by GitHub
parent 8849bd776b
commit 875b258977
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
bugfixes:
- conditionals - When displaying a broken conditional error or deprecation warning,
the origin of the non-boolean result is included (if available), and the raw result is omitted.

@ -6,7 +6,6 @@ from __future__ import annotations
import copy
import dataclasses
import enum
import textwrap
import typing as t
import collections.abc as c
import re
@ -560,9 +559,11 @@ class TemplateEngine:
bool_result = bool(result)
result_origin = Origin.get_tag(result) or Origin.UNKNOWN
msg = (
f'Conditional result was {textwrap.shorten(str(result), width=40)!r} of type {native_type_name(result)!r}, '
f'which evaluates to {bool_result}. Conditionals must have a boolean result.'
f'Conditional result ({bool_result}) was derived from value of type {native_type_name(result)!r} at {str(result_origin)!r}. '
'Conditionals must have a boolean result.'
)
if _TemplateConfig.allow_broken_conditionals:

Loading…
Cancel
Save