`ipaddress`: `subnet_of()` and `supernet_of()` raise confusing `TypeError` wrapping an `AttributeError` when passed an Address object
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans le module Python ipaddress, au niveau de _is_subnet_of, qui gère subnet_of() et supernet_of(), et reproduisez l’appel signalé avec un IPv6Address. Vérifiez que le fait de transmettre une adresse produit un TypeError explicite indiquant qu’un objet réseau est requis, plutôt que l’erreur de contenance encapsulée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- networking
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 30/100