Skip to content

Commit 32529ef

Browse files
authored
fix: Long{AboveMax,BelowMin} type-change error (#3634)
* 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> * test: focus long bound error assertions Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com> --------- Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
1 parent 3cce3d3 commit 32529ef

2 files changed

Lines changed: 14 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,18 @@ def test_below_min_int() -> None:
633633
assert b.to(IntegerType()) == IntBelowMin()
634634

635635

636+
def test_long_above_max_to_error() -> None:
637+
with pytest.raises(TypeError) as e:
638+
LongAboveMax().to(IntegerType())
639+
assert "Cannot change the type of LongAboveMax" in str(e.value)
640+
641+
642+
def test_long_below_min_to_error() -> None:
643+
with pytest.raises(TypeError) as e:
644+
LongBelowMin().to(IntegerType())
645+
assert "Cannot change the type of LongBelowMin" in str(e.value)
646+
647+
636648
def test_invalid_boolean_conversions() -> None:
637649
assert_invalid_conversions(
638650
literal(True),

0 commit comments

Comments
 (0)