Skip to content

Fix exception type for negative __length_hint__ return value#758

Open
jseop-lim wants to merge 1 commit intooracle:masterfrom
jseop-lim:GH757-length-hint-error
Open

Fix exception type for negative __length_hint__ return value#758
jseop-lim wants to merge 1 commit intooracle:masterfrom
jseop-lim:GH757-length-hint-error

Conversation

@jseop-lim
Copy link
Copy Markdown
Contributor

Description

Fixes #757

When __length_hint__() returns a negative integer, GraalPy raises TypeError instead of ValueError. CPython's PyObject_LengthHint (Objects/abstract.c:141-144) raises ValueError for this case.

AS-IS

TypeError: __length_hint__() should return >= 0

TO-BE

ValueError: __length_hint__() should return >= 0

(matching CPython)

Changes

  • Raise ValueError instead of TypeError for negative __length_hint__ return value in IteratorNodes.GetLength.length, matching CPython's PyObject_LengthHint. The adjacent non-integer branch continues to raise TypeError as before.

Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: list(): negative __length_hint__ raises TypeError instead of ValueError

1 participant