Skip to content

Commit cea052e

Browse files
committed
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>
1 parent 2c75523 commit cea052e

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

pyiceberg/expressions/literals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def __init__(self) -> None:
251251

252252
@singledispatchmethod
253253
def to(self, type_var: IcebergType) -> Literal: # type: ignore
254-
raise TypeError("Cannot change the type of IntAboveMax")
254+
raise TypeError("Cannot change the type of LongAboveMax")
255255

256256
@to.register(LongType)
257257
def _(self, _: LongType) -> Literal[int]:
@@ -264,7 +264,7 @@ def __init__(self) -> None:
264264

265265
@singledispatchmethod
266266
def to(self, type_var: IcebergType) -> Literal: # type: ignore
267-
raise TypeError("Cannot change the type of IntBelowMin")
267+
raise TypeError("Cannot change the type of LongBelowMin")
268268

269269
@to.register(LongType)
270270
def _(self, _: LongType) -> Literal[int]:

tests/expressions/test_literals.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,20 @@ def test_below_min_int() -> None:
633633
assert b.to(IntegerType()) == IntBelowMin()
634634

635635

636+
def test_above_max_long() -> None:
637+
a = LongAboveMax()
638+
with pytest.raises(TypeError) as e:
639+
a.to(IntegerType())
640+
assert "Cannot change the type of LongAboveMax" in str(e.value)
641+
642+
643+
def test_below_min_long() -> None:
644+
b = LongBelowMin()
645+
with pytest.raises(TypeError) as e:
646+
b.to(IntegerType())
647+
assert "Cannot change the type of LongBelowMin" in str(e.value)
648+
649+
636650
def test_invalid_boolean_conversions() -> None:
637651
assert_invalid_conversions(
638652
literal(True),

0 commit comments

Comments
 (0)