From cea052e67607f7b384a5aea24ae6efdfd47b67c4 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 1/2] 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. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com> --- pyiceberg/expressions/literals.py | 4 ++-- tests/expressions/test_literals.py | 14 ++++++++++++++ 2 files changed, 16 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..c5246c19d3 100644 --- a/tests/expressions/test_literals.py +++ b/tests/expressions/test_literals.py @@ -633,6 +633,20 @@ def test_below_min_int() -> None: assert b.to(IntegerType()) == IntBelowMin() +def test_above_max_long() -> None: + a = 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() + 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), From bce53ee1604828c51d18bb54a662b091b96b88e1 Mon Sep 17 00:00:00 2001 From: Anas Khan <83116240+anxkhn@users.noreply.github.com> Date: Tue, 14 Jul 2026 17:21:10 +0530 Subject: [PATCH 2/2] test: focus long bound error assertions Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com> --- tests/expressions/test_literals.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/expressions/test_literals.py b/tests/expressions/test_literals.py index c5246c19d3..9251e79a7d 100644 --- a/tests/expressions/test_literals.py +++ b/tests/expressions/test_literals.py @@ -633,17 +633,15 @@ def test_below_min_int() -> None: assert b.to(IntegerType()) == IntBelowMin() -def test_above_max_long() -> None: - a = LongAboveMax() +def test_long_above_max_to_error() -> None: with pytest.raises(TypeError) as e: - a.to(IntegerType()) + LongAboveMax().to(IntegerType()) assert "Cannot change the type of LongAboveMax" in str(e.value) -def test_below_min_long() -> None: - b = LongBelowMin() +def test_long_below_min_to_error() -> None: with pytest.raises(TypeError) as e: - b.to(IntegerType()) + LongBelowMin().to(IntegerType()) assert "Cannot change the type of LongBelowMin" in str(e.value)