Skip to content

Commit 5945e4b

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.
1 parent 2c75523 commit 5945e4b

2 files changed

Lines changed: 30 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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,34 @@ 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+
# singleton
639+
assert a == LongAboveMax()
640+
assert str(a) == "LongAboveMax"
641+
assert repr(a) == "LongAboveMax()"
642+
assert a.value == LongType.max
643+
assert a == eval(repr(a))
644+
assert a.to(LongType()) == LongAboveMax()
645+
with pytest.raises(TypeError) as e:
646+
a.to(IntegerType())
647+
assert "Cannot change the type of LongAboveMax" in str(e.value)
648+
649+
650+
def test_below_min_long() -> None:
651+
b = LongBelowMin()
652+
# singleton
653+
assert b == LongBelowMin()
654+
assert str(b) == "LongBelowMin"
655+
assert repr(b) == "LongBelowMin()"
656+
assert b == eval(repr(b))
657+
assert b.value == LongType.min
658+
assert b.to(LongType()) == LongBelowMin()
659+
with pytest.raises(TypeError) as e:
660+
b.to(IntegerType())
661+
assert "Cannot change the type of LongBelowMin" in str(e.value)
662+
663+
636664
def test_invalid_boolean_conversions() -> None:
637665
assert_invalid_conversions(
638666
literal(True),

0 commit comments

Comments
 (0)