IPv4Interface.is_loopback ignores the network prefix, unlike IPv6Interface
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
- gh-151786
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne bei IPv4Interface.is_loopback und vergleiche es mit der in der Issue gezeigten Implementierung von IPv6Interface. Prüfe die vorhandenen ipaddress-Tests und stelle sicher, dass ein Interface sowohl seine Adresse als auch sein Netzwerk berücksichtigt, einschließlich des dokumentierten Verhaltens von 127.0.0.1/4.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- networking
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100