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

Co-authored-by: Matt Clay <matt@mystile.com>
This commit is contained in:
Matt Davis
2025-08-18 15:35:39 -07:00
committed by GitHub
parent 558676fcdc
commit b1fc98c8ad
2 changed files with 7 additions and 3 deletions

View File

@@ -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.

View File

@@ -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: