`ipaddress`: `subnet_of()` and `supernet_of()` raise confusing `TypeError` wrapping an `AttributeError` when passed an Address object
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
Bug description:
When calling subnet_of() or supernet_of() on an IPv4Network or IPv6Network and passing an address object (e.g., IPv6Address) instead of a network object, the module attempts to access the network_address attribute on the address object. This raises an AttributeError, which is then caught by the broader exception handling in _is_subnet_of, resulting in a confusing TypeError that completely masks the original attribute access failure.
The method should explicitly check that the other argument is a network object (or at least raise a clear TypeError stating that a network object is required) rather than failing internally with an AttributeError that gets swallowed into a generic containment error.
Repro:
import ipaddress
ipaddress.IPv6Network('::/0').subnet_of(ipaddress.IPv6Address('::1'))
Traceback:
AttributeError: 'IPv6Address' object has no attribute 'network_address'
During handling of the above exception, another exception occurred:
TypeError: Unable to test subnet containment between ::/0 and ::1
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
- gh-154147
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia nel modulo Python ipaddress, in _is_subnet_of, che gestisce subnet_of() e supernet_of(), e riproduci la chiamata segnalata con un IPv6Address. Conferma che passare un indirizzo produca un TypeError chiaro che indichi che è richiesto un oggetto di rete, invece dell’errore di contenimento incapsulato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- networking
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 30/100