Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

IPv4Network and IPv6Network hosts method return different types when provided a /32 (ipv4) or /128 (ipv6) #109305

Open
Labels
type-bugAn unexpected behavior, bug, or error
@k0pak4

Description

@k0pak4

Bug report

Bug description:

when using a network with a subnet that only includes a single address (e.g., /32 on ipv4 and /128), the return type differs, which may cause issues if relying on one of the two types.

This results in a generator for a network with more than one address, vs a list for one address.

>>>importipaddress>>> type(ipaddress.ip_network('192.168.1.0/24').hosts())<class'generator'>>>>next(ipaddress.ip_network('192.168.1.0/24').hosts())IPv4Address('192.168.1.1')>>>type(ipaddress.ip_network('192.168.1.1/32').hosts())<class'list'>>>>next(ipaddress.ip_network('192.168.1.1/32').hosts())Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>TypeError:'list'objectisnotaniterator

Should a yield be added to the lambda in the hosts override inIPv4 andIPv6? (see below suggestion to make them both generators)

lambda: (yieldIPv4Address(addr))# or IPv6Address

This would make the return types consistent for all uses of hosts()

CPython versions tested on:

3.9

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp