Skip to content

Setting a string to start and step argument of itertools.count() gets a wrong error message #135284

Not planned
@hyperkai

Description

@hyperkai

Bug report

Bug description:

Setting a string to start and step argument of itertools.count() gets the error message as shown below:

from itertools import count

print(count(start='Hello')) # Error
print(count(step='World')) # Error

TypeError: a number is required

But setting a boolean value to start and step argument works as shown below:

from itertools import count

print(count(start=True)) # count(1)
print(count(step=False)) # count(0, False)

So, the error message should be the same as the one of range() as shown below:

print(range('Hello')) # Error

TypeError: 'str' object cannot be interpreted as an integer

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Activity

skirpichev

skirpichev commented on Jun 9, 2025

@skirpichev
Contributor

But booleans are integers (subclass). Error message looks correct for me.

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

    extension-modulesC modules in the Modules dirinvalidtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Setting a string to `start` and `step` argument of `itertools.count()` gets a wrong error message · Issue #135284 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant