Skip to content

Fix exception type for negative __length_hint__ return value#758

Merged
graalvmbot merged 2 commits intooracle:masterfrom
jseop-lim:GH757-length-hint-error
Apr 27, 2026
Merged

Fix exception type for negative __length_hint__ return value#758
graalvmbot merged 2 commits 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
Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
@msimacek msimacek self-requested a review April 27, 2026 07:29
Copy link
Copy Markdown
Contributor

@msimacek msimacek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution

@jseop-lim
Copy link
Copy Markdown
Contributor Author

CI failures unrelated - pre-existing infra/flaky tests

@graalvmbot graalvmbot merged commit 63f4972 into oracle:master Apr 27, 2026
51 of 57 checks passed
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

3 participants