Bug report
Bug description:
IPv4Interface does not override is_loopback, so it inherits IPv4Address.is_loopback and only checks the host address, ignoring the network. IPv6Interface, on the other hand, checks both the address and the network:
>>> import ipaddress
>>> ipaddress.IPv4Interface('127.0.0.1/4').is_loopback
True
>>> ipaddress.IPv4Interface('127.0.0.1/4').network.is_loopback
False
>>> ipaddress.IPv6Interface('::1/64').is_loopback
False
127.0.0.1/4 has a network of 112.0.0.0/4, which is not within the loopback range 127.0.0.0/8, yet is_loopback returns True.
This is the same class of inconsistency already fixed for is_unspecified in gh-115766: an interface property should consider both the address and its network. IPv6Interface.is_loopback already does this:
@property
def is_loopback(self):
return super().is_loopback and self.network.is_loopback
IPv4Interface should get the same override for consistency.
Note this is a behavior change (127.0.0.1/4 etc. would change from True to False).
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
IPv4Interfacedoes not overrideis_loopback, so it inheritsIPv4Address.is_loopbackand only checks the host address, ignoring the network.IPv6Interface, on the other hand, checks both the address and the network:127.0.0.1/4has a network of112.0.0.0/4, which is not within the loopback range127.0.0.0/8, yetis_loopbackreturnsTrue.This is the same class of inconsistency already fixed for
is_unspecifiedin gh-115766: an interface property should consider both the address and its network.IPv6Interface.is_loopbackalready does this:IPv4Interfaceshould get the same override for consistency.Note this is a behavior change (
127.0.0.1/4etc. would change fromTruetoFalse).CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs