Skip to content

fix: correct class name in Long{AboveMax,BelowMin} type-change error#3634

Open
anxkhn wants to merge 1 commit into
apache:mainfrom
anxkhn:patch-20
Open

fix: correct class name in Long{AboveMax,BelowMin} type-change error#3634
anxkhn wants to merge 1 commit into
apache:mainfrom
anxkhn:patch-20

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

LongAboveMax.to() and LongBelowMin.to() fall back to
raise TypeError("Cannot change the type of ...") when asked to convert to an
unsupported type, but the class name in each message was left as IntAboveMax /
IntBelowMin, a copy-paste leftover from the IntAboveMax / IntBelowMin
singletons defined just above. So when a long overflow sentinel is converted to
an unsupported type, the diagnostic misidentifies it as an int literal, which is
misleading when debugging.

For comparison, the neighbouring sentinels already name themselves correctly:
FloatAboveMax / FloatBelowMin, IntAboveMax / IntBelowMin. Only the two
Long* messages are wrong.

This is the same class of copy-paste-from-the-Int-handler slip that
DecimalLiteral.to(LongType) had in #3469 (fixed by #3470, which corrected the
returned sentinel object); this PR fixes the remaining instance in the
diagnostic messages on the Long* singletons themselves.

Change: point each message at its own class:

  • pyiceberg/expressions/literals.py LongAboveMax.to: IntAboveMax -> LongAboveMax
  • pyiceberg/expressions/literals.py LongBelowMin.to: IntBelowMin -> LongBelowMin

Are these changes tested?

Yes. Added test_above_max_long and test_below_min_long in
tests/expressions/test_literals.py, mirroring the existing test_above_max_int
/ test_below_min_int (singleton identity, str/repr, value, the successful
.to(LongType()) round-trip) and additionally asserting that .to(IntegerType())
raises TypeError whose message now names the Long* class.

Verified red -> green: reverting only the source change makes both new tests fail
with 'Cannot change the type of LongBelowMin' in 'Cannot change the type of IntBelowMin'; with the fix, both pass. tests/expressions/test_literals.py: 172
passed. tests/expressions/: 566 passed, no regressions. make lint (ruff,
ruff-format, mypy, pydocstyle, codespell, license/header) passes on the changed
files.

Are there any user-facing changes?

No API or behavior change. Only the text of an already-raised TypeError is
corrected (the exception type and the conditions under which it is raised are
unchanged). No changelog entry needed.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant