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
ipaddress_repro.py
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Bug report
Bug description:
When calling
subnet_of()orsupernet_of()on anIPv4NetworkorIPv6Networkand passing an address object (e.g.,IPv6Address) instead of a network object, the module attempts to access thenetwork_addressattribute on the address object. This raises anAttributeError, which is then caught by the broader exception handling in_is_subnet_of, resulting in a confusingTypeErrorthat completely masks the original attribute access failure.The method should explicitly check that the
otherargument is a network object (or at least raise a clearTypeErrorstating that a network object is required) rather than failing internally with anAttributeErrorthat gets swallowed into a generic containment error.Repro:
Traceback:
ipaddress_repro.py
CPython versions tested on:
3.14
Operating systems tested on:
macOS