fix: ValueTracker.evaluate() should not skip falsy values like 0

This commit is contained in:
KooshaPari 2026-09-12 23:12:04 -07:00
commit 84a2fa76b3
2 changed files with 25 additions and 1 deletions

View file

@ -490,7 +490,7 @@ class ValueTracker:
return "text"
def evaluate(self, value: object) -> None:
if not value or not self.couldbe:
if value is None or not self.couldbe:
return
not_these: list[str] = []
for name, test in self.couldbe.items():

View file

@ -102,3 +102,27 @@ def test_flatten(input, expected):
)
def test_dedupe_keys(input, expected):
assert utils.dedupe_keys(input) == expected
def test_value_tracker_evaluates_falsy_zero():
"""ValueTracker should evaluate 0 and narrow to integer"""
vt = utils.ValueTracker()
vt.evaluate(0)
vt.evaluate(0)
assert vt.guessed_type == "integer"
def test_value_tracker_evaluates_falsy_empty_string():
"""ValueTracker should evaluate empty strings and narrow to text"""
vt = utils.ValueTracker()
vt.evaluate("")
vt.evaluate("")
assert vt.guessed_type == "text"
def test_value_tracker_evaluates_falsy_false():
"""ValueTracker should evaluate False and narrow to integer (bool is subclass of int)"""
vt = utils.ValueTracker()
vt.evaluate(False)
vt.evaluate(False)
assert vt.guessed_type == "integer"