Change ipaddress._BaseNetwork.hosts return type#14658
Merged
srittau merged 1 commit intopython:mainfrom Aug 28, 2025
Merged
Conversation
Both `IPv4Network` and `IPv6Network` can return a single-element list instead of iterator.
ipaddress._BaseNetwork return typeipaddress._BaseNetwork return type
ipaddress._BaseNetwork return typeipaddress._BaseNetwork.hosts return type
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]
|
srittau
approved these changes
Aug 28, 2025
Collaborator
srittau
left a comment
There was a problem hiding this comment.
Yikes, that's some evil meta programming – and potentially quite unexpected for callers.
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
Member
|
It was a bug in Python. Fixed in python/cpython#141497. |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
So, TIL that both
IPv4NetworkandIPv6Networkcan return a single-element list instead of iterator by callingnextdirectly on result.Docs:
Source:
I guess it's a quite uncommon scenario, but nevertheless (IMO), stubs should reflect even the rarest situations.