From 5945e4bd42399e21f2a6780da89640266b727a7a Mon Sep 17 00:00:00 2001 From: Anas Khan <83116240+anxkhn@users.noreply.github.com> Date: Sun, 5 Jul 2026 01:29:48 +0530 Subject: [PATCH] fix: correct class name in Long{AboveMax,BelowMin} type-change error LongAboveMax.to() and LongBelowMin.to() raised a TypeError whose message named IntAboveMax/IntBelowMin, a copy-paste leftover from the Int singletons above them. When a long overflow literal is asked to convert to an unsupported type, the diagnostic misidentified it as an int literal, which is misleading when debugging. Point each message at its own class and add regression tests covering both the successful conversion and the corrected error message for the long singletons. --- pyiceberg/expressions/literals.py | 4 ++-- tests/expressions/test_literals.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pyiceberg/expressions/literals.py b/pyiceberg/expressions/literals.py index 20be711c02..39922fde33 100644 --- a/pyiceberg/expressions/literals.py +++ b/pyiceberg/expressions/literals.py @@ -251,7 +251,7 @@ def __init__(self) -> None: @singledispatchmethod def to(self, type_var: IcebergType) -> Literal: # type: ignore - raise TypeError("Cannot change the type of IntAboveMax") + raise TypeError("Cannot change the type of LongAboveMax") @to.register(LongType) def _(self, _: LongType) -> Literal[int]: @@ -264,7 +264,7 @@ def __init__(self) -> None: @singledispatchmethod def to(self, type_var: IcebergType) -> Literal: # type: ignore - raise TypeError("Cannot change the type of IntBelowMin") + raise TypeError("Cannot change the type of LongBelowMin") @to.register(LongType) def _(self, _: LongType) -> Literal[int]: diff --git a/tests/expressions/test_literals.py b/tests/expressions/test_literals.py index 33b41d5e4c..1cfa2a6a65 100644 --- a/tests/expressions/test_literals.py +++ b/tests/expressions/test_literals.py @@ -633,6 +633,34 @@ def test_below_min_int() -> None: assert b.to(IntegerType()) == IntBelowMin() +def test_above_max_long() -> None: + a = LongAboveMax() + # singleton + assert a == LongAboveMax() + assert str(a) == "LongAboveMax" + assert repr(a) == "LongAboveMax()" + assert a.value == LongType.max + assert a == eval(repr(a)) + assert a.to(LongType()) == LongAboveMax() + with pytest.raises(TypeError) as e: + a.to(IntegerType()) + assert "Cannot change the type of LongAboveMax" in str(e.value) + + +def test_below_min_long() -> None: + b = LongBelowMin() + # singleton + assert b == LongBelowMin() + assert str(b) == "LongBelowMin" + assert repr(b) == "LongBelowMin()" + assert b == eval(repr(b)) + assert b.value == LongType.min + assert b.to(LongType()) == LongBelowMin() + with pytest.raises(TypeError) as e: + b.to(IntegerType()) + assert "Cannot change the type of LongBelowMin" in str(e.value) + + def test_invalid_boolean_conversions() -> None: assert_invalid_conversions( literal(True),