Skip to content

gh-111442: Correct names for all 0's and all 1's hosts in Address objects, and deprecate incorrect names. #132421

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

davidgroves
Copy link

@davidgroves davidgroves commented Apr 11, 2025

Use the correct langauge for the all 0's and all 1's addresses in networking.

For example, IPv6Networks don't have a network or a broadcast address. While the subnet_router_anycast address has all the host bits set to 0, you would expect to see packets on the wire addressed to it, where in IPv4 you would not expect to see packets addressed to the network_address. The all 1's host address in IPv6 has no special meaning.

This change deprecates the use of network_address or broadcast_address for IPv6Networks, and introduces the subnet_router_anycast_address property.

Internally, it does this by changing most previous occurances in the NetworkBase class for network_address to first_address and broadcast_address to last_address, and using the address family specific names in each address families class.


📚 Documentation preview 📚: https://cpython-previews--132421.org.readthedocs.build/

@davidgroves davidgroves changed the title gh-111442: Don't correct names for all 0's and all 1's hosts and deprecate incorrect names. gh-111442: Correct names for all 0's and all 1's hosts and deprecate incorrect names. Apr 11, 2025
@davidgroves davidgroves changed the title gh-111442: Correct names for all 0's and all 1's hosts and deprecate incorrect names. gh-111442: Correct names for all 0's and all 1's hosts in Address objects, and deprecate incorrect names. Apr 11, 2025
@davidgroves
Copy link
Author

This is my first pull request to Python, or to be honest, any "major" OSS project in quite some time.

Please give me any advice / pointers / recommendations / insults as I'd also like to close out #125641 at some point.

@chris-eibl chris-eibl added the stdlib Python modules in the Lib dir label Apr 12, 2025
Copy link
Contributor

@brianschubert brianschubert left a comment

Choose a reason for hiding this comment

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

Thanks for putting togethor this PR! I noticed that there hasn't yet been any discussion on the issue or on DPO about this feature. It would be a good idea to open a thread on https://discuss.python.org/c/ideas/6 to get some feedback. In particular, it would be good to get a consensus about whether it makes sense to deprecate the existing attributes on IPv6Network.

I've added some general review comments below.

Comment on lines -759 to -760
.. attribute:: network_address
.. attribute:: broadcast_address
Copy link
Contributor

Choose a reason for hiding this comment

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

These shouldn't be removed quite yet - they'd need be documented during a deprecation period.

Copy link
Author

Choose a reason for hiding this comment

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

Readded

# is a given.
if last.broadcast_address >= net.broadcast_address:
if last.last_address >= net.last_address:
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing these names internally feels like an unnecessary cosmetic change. These make the diff harder for a core dev to review and may create backport conflicts in the future. Plus there's a risk of accidentally introducing a bug. It might be a good idea to revert these for now.

Copy link
Author

Choose a reason for hiding this comment

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

I see it both ways. This is touching a bunch of lines for seemingly no effect, but it also means someone new to reading the codebase should hopefully not be confused by things like why a IPv6Network has a test for its broadcast_address.

If everyone hates this, its obviously not a problem to revert the internal naming.

Comment on lines +1569 to +1575
@functools.cached_property
def broadcast_address(self):
return self.last_address

@functools.cached_property
def network_address(self):
return self.first_address
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, is there value in making these cached_propertys when they're just surrogates for last_address/first_address , which already are cached_propertys?

Copy link
Author

Choose a reason for hiding this comment

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

This made sense when you wrote it.

But they are slightly modified now to have different behaviour for /31's and /127's, reflecting the lack of a broadcast_address on those sized networks.

@@ -1393,16 +1393,6 @@ def testGetBroadcast(self):
self.assertEqual(int(self.ipv4_network.broadcast_address), 16909311)
self.assertEqual(str(self.ipv4_network.broadcast_address), '1.2.3.255')

self.assertEqual(int(self.ipv6_network.broadcast_address),
42540616829182469451850391367731642367)
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests should stay for now, even if it's decided that broadcast_address should be deprecated.

Copy link
Author

Choose a reason for hiding this comment

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

Readded with extra deprecation checks.

self.assertIn('hostmask', self.ipv6_network.__dict__)
self.assertIn('broadcast_address', self.ipv6_interface.network.__dict__)
self.assertIn('hostmask', self.ipv6_interface.network.__dict__)

Copy link
Contributor

Choose a reason for hiding this comment

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

Tests should be added for all the new attributes. Additionally, you'll need to update the tests that now raise deprecation warnings.

Copy link
Author

Choose a reason for hiding this comment

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

Added tests that check for the deprecation warnings when used on IPv6Networks.

@davidgroves
Copy link
Author

Thanks for putting togethor this PR! I noticed that there hasn't yet been any discussion on the issue or on DPO about this feature. some general review comments below.

I've created https://discuss.python.org/t/ipaddress-deprecate-network-address-broadcast-address-from-ipv6networks-add-subnet-router-anycast-and-terminology-cleanups/88099 to discuss this.

Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
@python-cla-bot
Copy link

python-cla-bot bot commented Apr 12, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review stdlib Python modules in the Lib dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants