python / python/cpython

Issues in ipaddress.collapse_addresses()

Offen
#149,722 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

3.13 3.14 3.15 3.16 stdlib type-bug type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug report

The following issues was discovered during reviewing #141842:

  • ipaddress.collapse_addresses() supports not only IP networks, but also IP addresses and a mix of them. There are dedicated tests, but this is not documented.
  • ipaddress.collapse_addresses() contains code for supporting also IP interfaces, but it always was broken (it would work if interfaces were not subclasses of addresses). The test for mix of IP addresses and IP interfaces is mislabeled (it says a mix of addresses and networks) and partially commented out (it only tests addresses now, which is mostly a duplicate of other test).
  • While TypeError is raised immediately for IP addresses of different versions and IP networks of different versions, it is delayed until the start of iteration for a mix of IP addresses and IP networks with addresses and networks having different versions.
  • For objects other that IP objects you can get AttributeError instead of TypeError.

My plan for a fix:

  • Document support of IP addresses.
  • Explicitly forbid IP interfaces.
  • Always raise TypeError for invalid types (the code is simpler this way).
  • Add tests for corner cases.

For new version only:

  • Implement support of IP interfaces and document it as a new feature.
  • Either raise TypeError immediately for IP objects of different versions, or remove redundant explicit checks, they will be raised implicitly in comparisons.
Linked PRs
  • gh-149723

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem Einstiegspunkt ipaddress.collapse_addresses() und den bestehenden dedizierten Tests, die im Bericht erwähnt werden. Prüfe den verknüpften PR gh-149723, bevor du das Verhalten änderst. Als abgeschlossen gilt die Dokumentation der unterstützten IP-Adressen, eine Entscheidung darüber, wie IP-Schnittstellen behandelt werden, das konsistente Auslösen von TypeError bei ungültigen Eingaben und das Hinzufügen von Tests für Randfälle.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.