Skip to content
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

gh-128810: Added .shorthand property to IPv4Network and IPv6Network in the ipaddress module #128811

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

Conversation

jfuruness
Copy link

@jfuruness jfuruness commented Jan 14, 2025

Pretty straightforward. Addresses gh-128810. Added a .shorthand property to all ip_networks for ease-of-use, since this is how they are commonly written by network operators. This way for a prefix 1.2.0.0/16 the shorthand of 1.2/16 can easily be accessed.

#128810

Copy link

cpython-cla-bot bot commented Jan 14, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jan 14, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@@ -0,0 +1 @@
Added a .shorthand function to IPv4Network and IPv6Network's in the ipaddress module to be able to display a prefix such as 1.2.0.0/16 as it's shorthand version (often used by network operators) as 1.2/16.
Copy link
Contributor

@rruuaanng rruuaanng Jan 14, 2025

Choose a reason for hiding this comment

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

Suggested change
Added a .shorthand function to IPv4Network and IPv6Network's in the ipaddress module to be able to display a prefix such as 1.2.0.0/16 as it's shorthand version (often used by network operators) as 1.2/16.
Add the :attr:`!shorthand` property to :class:`~ipaddress.IPv4Network` and :class:`~ipaddress.IPv6Network` in the :mod:`ipaddress` module to display a prefix such as ``1.2.0.0/16`` as its shorthand version (often used by network operators), like ``1.2/16``.

Edit

More tags, see https://devguide.python.org/documentation/markup/

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

We're still discussing approaches in the issue, and if we want to actually go for this (the RFC specifying this is a best practice rather than a standard).

That, and I don't like shorthand being the name, because that's not really what it's called universally. Something like cidr or cidr_shorthand would be more correct.

@jfuruness
Copy link
Author

I will update the PR shortly, still discussing the desired behavior as ZeroIntensity mentioned. Thank you all for your feedback!

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

Successfully merging this pull request may close these issues.

3 participants