class IPv4Network hosts function does not work when prefixlen is /31
Normally, the class IPv4Network "hosts" function is modified to "iter" when mask is /31. This works well when the network is a string, however when the network is an integer, it does not work.
In the init function of the class, there are two conditions upon which the hosts function is not adjusted:
if isinstance(address, (_compat_int_types, bytes)):
if isinstance(address, tuple):
Modification of hosts, only applies when both conditions are failing:
if self._prefixlen == (self._max_prefixlen - 1): self.hosts = self.iter
The problem has been discovered when using exclude_address, the result is an iterator of IPv4Network objects created using integers. hosts function does not work when one of the remaining IPv4Network is a /31.
Is this problem already fixed in CPython ipaddress module? If not, it might make sense to open a bug report on https://bugs.python.org/