python / python/cpython

`ipaddress`: `subnet_of()` and `supernet_of()` raise confusing `TypeError` wrapping an `AttributeError` when passed an Address object

Aberta
#153,769 8 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

stdlib type-bug
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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

Linked PRs
  • gh-154147

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece no módulo ipaddress do Python, em _is_subnet_of, que trata de subnet_of() e supernet_of(), e reproduza a chamada relatada com um IPv6Address. Confirme que passar um endereço produz um TypeError claro informando que um objeto de rede é necessário, em vez do erro de contenção encapsulado.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
networking
Tipo de issue
Bug
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Estagnada
Clareza
Claramente especificada
Facilidade para iniciantes
30/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.