Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Open
Description
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