Skip to content

Change ipaddress._BaseNetwork.hosts return type#14658

Merged
srittau merged 1 commit intopython:mainfrom
kapkekes:patch-1
Aug 28, 2025
Merged

Change ipaddress._BaseNetwork.hosts return type#14658
srittau merged 1 commit intopython:mainfrom
kapkekes:patch-1

Conversation

@kapkekes
Copy link
Copy Markdown
Contributor

@kapkekes kapkekes commented Aug 28, 2025

So, TIL that both IPv4Network and IPv6Network can return a single-element list instead of iterator by calling next directly on result.

Docs:

Source:

I guess it's a quite uncommon scenario, but nevertheless (IMO), stubs should reflect even the rarest situations.

Both `IPv4Network` and `IPv6Network` can return a single-element list instead of iterator.
@kapkekes kapkekes changed the title Fix ipaddress._BaseNetwork return type Change ipaddress._BaseNetwork return type Aug 28, 2025
@kapkekes kapkekes changed the title Change ipaddress._BaseNetwork return type Change ipaddress._BaseNetwork.hosts return type Aug 28, 2025
@github-actions
Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/hybrid.py:834: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/hybrid.py:834: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
- discord/ext/commands/hybrid.py:858: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/hybrid.py:858: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
- discord/ext/commands/hybrid.py:883: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/hybrid.py:883: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
- discord/ext/commands/hybrid.py:935: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/hybrid.py:935: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
- discord/ext/commands/bot.py:290: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/bot.py:290: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
- discord/ext/commands/bot.py:314: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/bot.py:314: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]

Copy link
Copy Markdown
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes, that's some evil meta programming – and potentially quite unexpected for callers.

@srittau srittau merged commit c0fed91 into python:main Aug 28, 2025
63 checks passed
ipspace added a commit to ipspace/netlab that referenced this pull request Sep 12, 2025
mypy release 1.18.1 includes stricter checks of ipaddress return
values, so we have to wrap the iterator of IPv6 hosts into another
iterator just to keep it happy :(

See python/typeshed#14658 for details
ipspace added a commit to ipspace/netlab that referenced this pull request Sep 14, 2025
mypy release 1.18.1 includes stricter checks of ipaddress return
values, so we have to wrap the iterator of IPv6 hosts into another
iterator just to keep it happy :(

See python/typeshed#14658 for details
@serhiy-storchaka
Copy link
Copy Markdown
Member

It was a bug in Python. Fixed in python/cpython#141497.

@kapkekes
Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka, it's great to hear that!

At the moment, I wasn't bold enough to propose a breaking change, but I'm glad to hear that the trap has been removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants