python / python/cpython

IPv4Interface.is_loopback ignores the network prefix, unlike IPv6Interface

未关闭
#151,785 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:

IPv4Interface does not override is_loopback, so it inherits IPv4Address.is_loopback and only checks the host address, ignoring the network. IPv6Interface, on the other hand, checks both the address and the network:

>>> import ipaddress
>>> ipaddress.IPv4Interface('127.0.0.1/4').is_loopback
True
>>> ipaddress.IPv4Interface('127.0.0.1/4').network.is_loopback
False
>>> ipaddress.IPv6Interface('::1/64').is_loopback
False

127.0.0.1/4 has a network of 112.0.0.0/4, which is not within the loopback range 127.0.0.0/8, yet is_loopback returns True.

This is the same class of inconsistency already fixed for is_unspecified in gh-115766: an interface property should consider both the address and its network. IPv6Interface.is_loopback already does this:

@property
def is_loopback(self):
    return super().is_loopback and self.network.is_loopback

IPv4Interface should get the same override for consistency.

Note this is a behavior change (127.0.0.1/4 etc. would change from True to False).

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-151786

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 IPv4Interface.is_loopback 开始,并将其与 issue 中所示的 IPv6Interface 实现进行比较。检查现有的 ipaddress 测试,并确保接口同时考虑其地址和网络,包括文档中说明的 127.0.0.1/4 行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
networking
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。