Skip to content

[Bug]: itertools.count() accepts None for start and step #1251

Open

Description

@jseop-lim

Describe the bug

itertools.count(None) and itertools.count(0, None) return count(0) on GraalPy. CPython raises TypeError: a number is required, since only an omitted start or step takes the default.

Operating system

macOS

CPU architecture

ARM64

GraalPy version

master a3009f9 (Python 3.13.14); also reproduced on 25.1.3 (Python 3.12.8)

JDK version

No response

Context configuration

No response

Steps to reproduce

import itertools
print(itertools.count(None))
print(itertools.count(0, None))

GraalPy master a3009f9:

count(0)
count(0)

Expected behavior

CPython 3.13.14 (same on 3.12.13), for each call:

TypeError: a number is required

Stack trace

Additional context

The keyword forms count(start=None) and count(step=None) behave the same. A non-number other than None, such as count('a'), already raises the TypeError.

Root Cause

CountBuiltins.CountNode declares start and step with useDefaultForNone = true (CountBuiltins.java#L101-L104), so an explicit None becomes 0 or 1 before the PyNumberCheckNode checks (#L123-L128). CPython's clinic defaults only a missing argument (c_default="NULL"), and itertools_count_impl passes None to PyNumber_Check (itertoolsmodule.c#L4022-L4026).

Fix Suggestion

Drop useDefaultForNone = true from both @ArgumentClinic annotations, so the defaults apply only to an omitted argument.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions