gh-141497: make ipaddress.IP{v4,v6}Network.hosts() return an iterator#141547
gh-141497: make ipaddress.IP{v4,v6}Network.hosts() return an iterator#141547serhiy-storchaka merged 10 commits intopython:mainfrom
ipaddress.IP{v4,v6}Network.hosts() return an iterator#141547Conversation
dr-carlos
left a comment
There was a problem hiding this comment.
A short test should be added in the relevant part(s) of test_ipaddress.py to ensure that the hosts() method always returns an iterator.
There was a problem hiding this comment.
The tests looks good, but this should still pass on main. Could you add similar tests for the specific cases affected by this PR?
cpython/Lib/test/test_ipaddress.py
Lines 1507 to 1510 in 17a1a05
cpython/Lib/test/test_ipaddress.py
Lines 1525 to 1527 in 17a1a05
the workflow shows an error in test import, I think it is a known issue I saw it somewhere.... |
sharktide
left a comment
There was a problem hiding this comment.
Although we probably should re-run the failed test. It seems unrelated.
|
Is there a way to rerun the workflow?? I don't see any in checks |
You can't, a core developer or official triager has to. I am not officially either. It is fine for now. They probably will when they see this PR of you haven't pushed any commits in the meantime because losing commits re-runs all tests. |
sharktide
left a comment
There was a problem hiding this comment.
Core review? @serhiy-storchaka
iterableipaddress.IPv4Network.hosts() an iterable
ipaddress.IPv4Network.hosts() an iterableipaddress.IP{v4,v6}Network.hosts() an iterable
ipaddress.IP{v4,v6}Network.hosts() an iterableipaddress.IP{v4,v6}Network.hosts() return an iterator
Misc/NEWS.d/next/Library/2025-11-14-16-24-20.gh-issue-141497.L_CxDJ.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Library/2025-11-14-16-24-20.gh-issue-141497.L_CxDJ.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Library/2025-11-14-16-24-20.gh-issue-141497.L_CxDJ.rst
Outdated
Show resolved
Hide resolved
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
Thanks @XChaitanyaX for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
Thanks @XChaitanyaX for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Sorry, @XChaitanyaX and @serhiy-storchaka, I could not cleanly backport this to |
…ning an iterator (pythonGH-141547) (cherry picked from commit 6b1bdf6) Co-authored-by: Krishna Chaitanya <141550576+XChaitanyaX@users.noreply.github.com>
|
GH-141673 is a backport of this pull request to the 3.14 branch. |
|
Should I make a pr for 3.13?? @serhiy-storchaka |
|
If it's not too difficult for you. Otherwise, I'll do it. |
|
GH-141695 is a backport of this pull request to the 3.13 branch. |
|
For other users coming across this issue: this is a breaking change. Ran into this while upgrading a 3.11 project to 3.13. One environment uses 3.13.11 and chokes on /128s and /32s: single_ip_address_with_cidr = '10.40.1.1/32'
def single_ip_address_with_cidr_to_ip_address(single_ip_address_with_cidr: str) -> str:
"""Transform a single IP address with CIDR (185.233.172.0/32) to a CIDR-less version (e.g. 185.233.172.0)."""
> return str(ipaddress.ip_network(single_ip_address_with_cidr).hosts()[0]) # type: ignore[index]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E TypeError: 'tuple_iterator' object is not subscriptable... whereas another environment on 3.13.5 is fine. |
|
I don't think it's correct to use
The fact that someone is using |
Uh oh!
There was an error while loading. Please reload this page.