Skip to content

Incomplete return type for ipaddress.IPv4Network.hosts() #141497

Closed

Description

@elWanderero

Documentation

(And also for ipaddress.IPv6Network.hosts())

In https://docs.python.org/3/library/ipaddress.html#ipaddress.IPv4Network.hosts and https://docs.python.org/3/library/ipaddress.html#ipaddress.IPv6Network.hosts the hosts() method is documented as returning an iterator, when in reality it can return an iterator or a list.

This extra return possibilty can be seen in

self.hosts = lambda: [IPv4Address(addr)]
and
self.hosts = lambda: [IPv6Address(addr)]

and was introduced in 2020 in 8e9c47a, but was fixed only recently in typeshed: python/typeshed@c0fed91

Linked PRs

Activity

  1. serhiy-storchaka commented on Nov 13, 2025

    @serhiy-storchaka
    Member

    Returning an iterator or a list looks bad design. It should either always return an iterator (so next() works) or a re-iterable iterable.

    I think that we can consider 8e9c47a introducing a bug. hosts should return not [IPv4Address(addr)], but iter([IPv4Address(addr)]).

  2. added
    type-bugAn unexpected behavior, bug, or error
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    and removed
    docsDocumentation in the Doc dir
    on Nov 13, 2025
  3. XChaitanyaX commented on Nov 14, 2025

    @XChaitanyaX
    Contributor

    working on this...

  4. added
    stdlibStandard Library Python modules in the Lib/ directory
    and removed on Nov 14, 2025
  5. added a commit that references this issue on Nov 17, 2025
  6. added a commit that references this issue on Nov 17, 2025
  7. added 2 commits that reference this issue on Nov 17, 2025
  8. serhiy-storchaka commented on Nov 18, 2025

    @serhiy-storchaka
    Member

    Thank you for your report @elWanderero and your PR @XChaitanyaX.

    I guess typeshed should fix this back.

  9. added a commit that references this issue on Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.13only security fixes3.14bugs and security fixes3.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions