-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-141497: make ipaddress.IP{v4,v6}Network.hosts() return an iterator
#141547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
dr-carlos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
| # special case where the network is a /32 | |
| addrs = [ipaddress.IPv4Address('1.2.3.4')] | |
| str_args = '1.2.3.4/32' | |
| tpl_args = ('1.2.3.4', 32) |
cpython/Lib/test/test_ipaddress.py
Lines 1525 to 1527 in 17a1a05
| addrs = [ipaddress.IPv6Address('2001:658:22a:cafe::1'), ] | |
| str_args = '2001:658:22a:cafe::1/128' | |
| tpl_args = ('2001:658:22a:cafe::1', 128) |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
sharktide
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
|
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 <[email protected]>
|
GH-141673 is a backport of this pull request to the 3.14 branch. |
…rning an iterator (GH-141547) (GH-141673) (cherry picked from commit 6b1bdf6) Co-authored-by: Krishna Chaitanya <[email protected]>
|
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. |
…rning an iterator (GH-141547) (GH-141695) (cherry picked from commit 6b1bdf6) Co-authored-by: Krishna Chaitanya <[email protected]>
|
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.